#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 100;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
struct Point {
  int x, y;
  Point(int a = 0, int b = 0) { x = a, y = b; }
};
int N, M, K;
Point o[maxn * maxn];
int col[maxn][maxn], pic[maxn * maxn], cnt;
char s[maxn][maxn];
void bfs(int x, int y, int c) {
  int h = 0, t = 0, g = 0;
  o[h] = Point(x, y);
  col[x][y] = c;
  for (; h <= t; ++h) {
    int x = o[h].x, y = o[h].y;
    for (int i = (0), _i = (3); i <= _i; i++) {
      int xx = dx[i] + x, yy = dy[i] + y;
      if (xx < 1 || yy < 1 || xx > N || yy > M) continue;
      if (col[xx][yy]) continue;
      if (s[xx][yy] == '*') {
        ++g;
        continue;
      }
      o[++t] = Point(xx, yy);
      col[xx][yy] = c;
    }
  }
  pic[c] = g;
}
int main() {
  for (; scanf("%d%d%d", &N, &M, &K) != EOF;) {
    for (int i = (1), _i = (N); i <= _i; i++) scanf("%s", s[i] + 1);
    memset(col, 0, sizeof(col));
    cnt = 0;
    for (int i = (1), _i = (N); i <= _i; i++)
      for (int j = (1), _j = (M); j <= _j; j++)
        if (!col[i][j] && s[i][j] == '.') bfs(i, j, ++cnt);
    for (int i = (1), _i = (K); i <= _i; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      printf("%d\n", pic[col[x][y]]);
    }
  }
  return 0;
}
