#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, tot, minx, maxx, miny, maxy, ans, val[1005][1005],
    vis[1005][1005];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
char str[1005][1005];
void dfs(int x, int y) {
  if (vis[x][y] != tot) vis[x][y] = tot;
  int tx, ty;
  for (int i = 0; i < 4; i++) {
    tx = x + dx[i];
    ty = y + dy[i];
    if (tx > 0 && tx <= n && ty > 0 && ty <= m) {
      if (str[tx][ty] == '*')
        ans++;
      else if (vis[tx][ty] != tot)
        vis[tx][ty] = tot, dfs(tx, ty);
    }
  }
}
void gval(int x, int y) {
  int tx, ty;
  for (int i = 0; i < 4; i++) {
    tx = x + dx[i];
    ty = y + dy[i];
    if (tx > 0 && tx <= n && ty > 0 && ty <= m && str[tx][ty] == '.' &&
        !val[tx][ty])
      val[tx][ty] = ans, gval(tx, ty);
  }
}
int main(void) {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  while (k--) {
    cin >> x >> y;
    if (str[x][y] == '*' || val[x][y]) {
      cout << val[x][y] << endl;
      continue;
    }
    minx = maxx = x;
    miny = maxy = y;
    tot++;
    ans = 0;
    dfs(x, y);
    gval(x, y);
    cout << ans << endl;
  }
  return 0;
}
