#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int dr[4] = {0, 1, 0, -1};
int dc[4] = {1, 0, -1, 0};
char grid[N][N];
bool vis[N][N];
int prnt[N][N];
int all[N * N];
int n, m;
void DFS(int r, int c, int num) {
  if (grid[r][c] == '*') {
    all[num]++;
    return;
  }
  if (vis[r][c]) return;
  vis[r][c] = true;
  prnt[r][c] = num;
  for (int i = 0; i < 4; i++) {
    int nr = r + dr[i];
    int nc = c + dc[i];
    if (nr >= 0 && nr < n && nc >= 0 && nc < m) DFS(nr, nc, num);
  }
}
int main() {
  int k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char x;
      scanf(" %c", &x);
      grid[i][j] = x;
    }
  }
  int now = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && grid[i][j] == '.') {
        DFS(i, j, now);
        now++;
      }
    }
  }
  while (k--) {
    int r, c;
    scanf("%d%d", &r, &c);
    r--;
    c--;
    int num = prnt[r][c];
    printf("%d\n", all[num]);
  }
  return 0;
}
