#include <bits/stdc++.h>
using namespace std;
int N, M, k, ans[1000001], c, id[(long long)1e3 + 3][(long long)1e3 + 3];
bool vis[(long long)1e3 + 3][(long long)1e3 + 3];
char a[(long long)1e3 + 3][(long long)1e3 + 3];
int x[] = {1, -1, 0, 0};
int y[] = {0, 0, -1, 1};
void cnt(int i, int j) {
  if (i && a[i - 1][j] == '*') {
    ans[c]++;
  }
  if (j && a[i][j - 1] == '*') {
    ans[c]++;
  }
  if (i < N - 1 && a[i + 1][j] == '*') {
    ans[c]++;
  }
  if (j < M - 1 && a[i][j + 1] == '*') {
    ans[c]++;
  }
}
void dfs(int i, int j) {
  vis[i][j] = 1;
  id[i][j] = c;
  cnt(i, j);
  for (int d = 0; d < 4; d++) {
    int u = i + x[d], v = j + y[d];
    if (a[u][v] == '.' && !vis[u][v]) {
      dfs(u, v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> k;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cin >> a[i][j];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (!vis[i][j] && a[i][j] == '.') {
        dfs(i, j);
        c++;
      }
    }
  }
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << ans[id[x][y]] << "\n";
  }
  return 0;
}
