#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
char s[N][N];
int n, m, k, c, id[N][N], z[N * N], dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
void go(int x, int y) {
  s[x][y] = 'o';
  id[x][y] = c;
  for (int d = 0; d < 4; ++d) {
    int u = x + dx[d], v = y + dy[d];
    if ('.' == s[u][v])
      go(u, v);
    else if ('*' == s[u][v])
      ++z[c];
  }
}
int main(void) {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if ('.' == s[i][j]) go(i, j), ++c;
  for (int i = 0, x, y; i < k && cin >> x >> y; ++i)
    cout << z[id[x - 1][y - 1]] << endl;
}
