#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2, M = 1e6 + 10;
char a[N][N];
int i, j, n, m, x, y, k, id, number, vis[N][N], num[N][N], ans[M];
int di[4] = {0, 0, 1, -1};
int dj[4] = {1, -1, 0, 0};
int valid(int i, int j) {
  return (i >= 0 && i < n && j >= 0 && j < m && !vis[i][j]);
}
void dfs(int i, int j) {
  vis[i][j] = 1;
  num[i][j] = id;
  for (int k = 0; k < 4; k++) {
    int ni = i + di[k];
    int nj = j + dj[k];
    if (valid(ni, nj)) {
      if (a[ni][nj] == '.')
        dfs(ni, nj);
      else
        number++;
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (!vis[i][j] && a[i][j] == '.') {
        number = 0;
        id++;
        dfs(i, j);
        ans[id] = number;
      }
  while (k--) {
    cin >> x >> y;
    cout << ans[num[x - 1][y - 1]] << endl;
  }
  return 0;
}
