#include <bits/stdc++.h>
using namespace std;
long long k, n, m;
char c[1001][1001];
long long vis[1001][1001] = {0}, t = 1, ans[1000001] = {0},
          vis2[1001][1001] = {0};
void read() {
  cin >> n >> m >> k;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      cin >> c[i][j];
    }
  }
}
void dfs(long long i, long long j) {
  if (vis[i][j] > 0) return;
  vis[i][j] = t;
  if (c[i + 1][j] != '*') dfs(i + 1, j);
  if (c[i - 1][j] != '*') dfs(i - 1, j);
  if (c[i][j + 1] != '*') dfs(i, j + 1);
  if (c[i][j - 1] != '*') dfs(i, j - 1);
}
long long dfs2(long long i, long long j) {
  vis2[i][j] = t;
  if (c[i][j] == '*') {
    vis2[i][j] = 0;
    return 1;
  }
  long long temp = 0;
  if (vis2[i - 1][j] != t) temp += dfs2(i - 1, j);
  if (vis2[i + 1][j] != t) temp += dfs2(i + 1, j);
  if (vis2[i][j - 1] != t) temp += dfs2(i, j - 1);
  if (vis2[i][j + 1] != t) temp += dfs2(i, j + 1);
  return temp;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  read();
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (vis[i][j] == 0 && c[i][j] == '.') {
        dfs(i, j);
        t++;
      }
    }
  }
  t = 1;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (vis[i][j] == t) {
        ans[t] = dfs2(i, j);
        t++;
      }
    }
  }
  while (k--) {
    long long x, y;
    cin >> x >> y;
    cout << ans[vis[x][y]] << '\n';
  }
}
