#include <bits/stdc++.h>
using namespace std;
int row, col;
int visited[2020][2020];
int ans[2020][2020];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
char a[2020][2020];
int bfs(int z, int x, int y) {
  int k, l;
  visited[x][y] = 1;
  queue<pair<int, int> > q;
  queue<pair<int, int> > s;
  q.push(make_pair(x, y));
  s.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    for (int j = 0; j < 4; j++) {
      k = p.first + dx[j];
      l = p.second + dy[j];
      if (k < row && k >= 0 && l < col && l >= 0) {
        if (a[k][l] == '*') {
          z = z + 1;
          continue;
        }
        if (a[k][l] == '.' && visited[k][l] == 0) {
          q.push(make_pair(k, l));
          s.push(make_pair(k, l));
          visited[k][l] = 1;
        }
      }
    }
    q.pop();
  }
  while (!s.empty()) {
    ans[s.front().first][s.front().second] = z;
    s.pop();
  }
  return z;
}
int main() {
  memset(visited, 0, sizeof(visited));
  memset(ans, -1, sizeof(ans));
  int k, X, Y, z;
  scanf("%d%d%d", &row, &col, &k);
  getchar();
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++) {
      cin >> a[i][j];
    }
  }
  memset(visited, 0, sizeof(visited));
  for (int n = 0; n < k; n++) {
    scanf("%d%d", &X, &Y);
    int p = 0, g;
    if (ans[X - 1][Y - 1] == -1) {
      g = bfs(p, X - 1, Y - 1);
      printf("%d\n", g);
    } else {
      printf("%d\n", ans[X - 1][Y - 1]);
    }
  }
}
