#include <bits/stdc++.h>
using namespace std;
const int maxN = 1005;
const int maxK = 505;
const int mod = (int)1e9 + 7;
const int inf = (int)1e9;
char tab[maxN][maxN];
int n, m;
bool visited[maxN][maxN];
int c[maxN][maxN];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
bool isValid(int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m && tab[x][y] == '.';
}
int memo[maxN * maxN];
int counter;
int dfs(int x, int y) {
  visited[x][y] = true;
  c[x][y] = counter;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    int xnew = x + dx[i];
    int ynew = y + dy[i];
    if (isValid(xnew, ynew) && !visited[xnew][ynew]) {
      ans += dfs(xnew, ynew);
    }
    if (!isValid(xnew, ynew)) {
      ans++;
    }
  }
  return ans;
}
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) {
    scanf("%s", tab[i]);
  }
  memset(c, -1, sizeof c);
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    if (c[x][y] == -1) {
      memo[counter] = dfs(x, y);
      counter++;
    }
    printf("%d\n", memo[c[x][y]]);
  }
  return 0;
}
