#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int f[maxn][maxn];
char line[maxn];
set<pair<int, int>> u;
int sol = 0;
void fill(int x, int y) {
  f[x][y] = 0;
  u.erase(make_pair(x, y));
  if (f[x + 1][y] == -1) {
    fill(x + 1, y);
  } else if (f[x + 1][y] == -2) {
    sol++;
  }
  if (f[x - 1][y] == -1) {
    fill(x - 1, y);
  } else if (f[x - 1][y] == -2) {
    sol++;
  }
  if (f[x][y + 1] == -1) {
    fill(x, y + 1);
  } else if (f[x][y + 1] == -2) {
    sol++;
  }
  if (f[x][y - 1] == -1) {
    fill(x, y - 1);
  } else if (f[x][y - 1] == -2) {
    sol++;
  }
}
void fill(int x, int y, int v) {
  f[x][y] = v;
  if (f[x + 1][y] == 0) {
    fill(x + 1, y, v);
  }
  if (f[x - 1][y] == 0) {
    fill(x - 1, y, v);
  }
  if (f[x][y + 1] == 0) {
    fill(x, y + 1, v);
  }
  if (f[x][y - 1] == 0) {
    fill(x, y - 1, v);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int k;
  scanf("%d", &k);
  for (int i = 1; i <= (int)(n); (i)++) {
    scanf("%s", line);
    f[i][0] = -2;
    f[i][m + 1] = -2;
    for (int j = 1; j <= (int)(m); (j)++)
      if (line[j] == '.') {
        f[i][j] = -1;
        u.insert(make_pair(i, j));
      } else {
        f[i][j] = -2;
      }
  }
  for (int j = (int)(0); j < (int)(m + 2); (j)++) f[0][j] = f[n + 1][j] = -2;
  while (!u.empty()) {
    sol = 0;
    auto cur = *u.begin();
    u.erase(cur);
    fill(cur.first, cur.second);
    fill(cur.first, cur.second, sol);
  }
  for (int i = 0; i < (int)(k); (i)++) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", f[x][y - 1]);
  }
  return 0;
}
