#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
int n, m, k;
char maze[1005][1005];
int num[1005][1005];
int a[1005 * 1005];
int cnt;
int id = 0;
void dfs(int x, int y) {
  num[x][y] = id;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && !num[nx][ny]) {
      if (maze[nx][ny] == '*') {
        cnt++;
      } else {
        dfs(nx, ny);
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  memset(num, 0, sizeof(num));
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> maze[i][j];
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (maze[i][j] == '.' && !num[i][j]) {
        id++;
        cnt = 0;
        dfs(i, j);
        a[id] = cnt;
      }
    }
  while (k--) {
    int x, y;
    cin >> x >> y;
    cout << a[num[x - 1][y - 1]] << endl;
  }
  return 0;
}
