import sys
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip('\n')
visited = []
out = []
for i in range(1010):
visited.append([])
out.append([])
for j in range(1010):
visited[i].append(0)
out[i].append(-1)
cells = []
def dfs(x,y):
global c
if x >= n or x < 0 or y >= m or y < 0:
return
if l[x][y] == '*':
c += 1
return
if visited[x][y] :
return
visited[x][y] = 1
cells.append((x,y))
dfs(x+1,y)
dfs(x,y+1)
dfs(x-1,y)
dfs(x,y-1)
n , m , k = get_ints()
l = []
for i in range(n):
l.append(list(input()))
for i in range(n):
for j in range(m):
if not visited[i][j] and l[i][j] == '.':
c = 0
dfs(i,j)
for x in cells:
if visited[x[0]][x[1]] and out[x[0]][x[1]] == -1:
out[x[0]][x[1]] = c
cells.clear()
for i in range(k):
x , y = get_ints()
x , y = x-1 , y-1
ans = out[x][y]
print(ans)
aW1wb3J0IHN5cwoKZGVmIGdldF9hcnJheSgpOiByZXR1cm4gbGlzdChtYXAoaW50LCBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpKSkKZGVmIGdldF9pbnRzKCk6IHJldHVybiBtYXAoaW50LCBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpKQpkZWYgaW5wdXQoKTogcmV0dXJuIHN5cy5zdGRpbi5yZWFkbGluZSgpLnN0cmlwKCdcbicpCgoKdmlzaXRlZCA9IFtdCm91dCA9IFtdCgpmb3IgaSBpbiByYW5nZSgxMDEwKToKICAgIHZpc2l0ZWQuYXBwZW5kKFtdKQogICAgb3V0LmFwcGVuZChbXSkKICAgIGZvciBqIGluIHJhbmdlKDEwMTApOgogICAgICAgIHZpc2l0ZWRbaV0uYXBwZW5kKDApCiAgICAgICAgb3V0W2ldLmFwcGVuZCgtMSkKY2VsbHMgPSBbXQpkZWYgZGZzKHgseSk6CiAgICBnbG9iYWwgYwogICAgaWYgeCA+PSBuIG9yIHggPCAwIG9yIHkgPj0gbSBvciB5IDwgMDoKICAgICAgICByZXR1cm4KICAgIGlmIGxbeF1beV0gPT0gJyonOgogICAgICAgIGMgKz0gMQogICAgICAgIHJldHVybgogICAgaWYgdmlzaXRlZFt4XVt5XSA6CiAgICAgICByZXR1cm4KICAgIHZpc2l0ZWRbeF1beV0gPSAxCiAgICBjZWxscy5hcHBlbmQoKHgseSkpCiAgICBkZnMoeCsxLHkpCiAgICBkZnMoeCx5KzEpCiAgICBkZnMoeC0xLHkpCiAgICBkZnMoeCx5LTEpCgpuICwgbSAsIGsgPSBnZXRfaW50cygpCmwgPSBbXQpmb3IgaSBpbiByYW5nZShuKToKICAgIGwuYXBwZW5kKGxpc3QoaW5wdXQoKSkpCgpmb3IgaSBpbiByYW5nZShuKToKICAgIGZvciBqIGluIHJhbmdlKG0pOgogICAgICAgIGlmIG5vdCB2aXNpdGVkW2ldW2pdIGFuZCBsW2ldW2pdID09ICcuJzoKICAgICAgICAgICAgYyA9IDAKICAgICAgICAgICAgZGZzKGksaikKICAgICAgICAgICAgZm9yIHggaW4gY2VsbHM6CiAgICAgICAgICAgICAgICBpZiB2aXNpdGVkW3hbMF1dW3hbMV1dIGFuZCBvdXRbeFswXV1beFsxXV0gPT0gLTE6CiAgICAgICAgICAgICAgICAgICAgb3V0W3hbMF1dW3hbMV1dID0gYwogICAgICAgICAgICBjZWxscy5jbGVhcigpCmZvciBpIGluIHJhbmdlKGspOgogICAgeCAsIHkgPSBnZXRfaW50cygpCiAgICB4ICwgeSA9IHgtMSAsIHktMQogICAgYW5zID0gb3V0W3hdW3ldCiAgICBwcmludChhbnMpCg==