#include <bits/stdc++.h>
using namespace std;
char mp[1010][1010];
int num[1010][1010];
int vis[1010][1010];
int ans[1000010], cur = 0;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int n, m, k;
int bfs(int X, int Y) {
  queue<pair<int, int> > qu;
  qu.push({X, Y});
  vis[X][Y] = ++cur;
  int tol = 0;
  while (!qu.empty()) {
    int x = qu.front().first;
    int y = qu.front().second;
    qu.pop();
    if (x > 1 && mp[x - 1][y] == '*') tol++;
    if (y > 1 && mp[x][y - 1] == '*') tol++;
    if (x < n && mp[x + 1][y] == '*') tol++;
    if (y < m && mp[x][y + 1] == '*') tol++;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx > 0 && nx <= n && ny > 0 && ny <= m && !vis[nx][ny] &&
          mp[nx][ny] == '.') {
        vis[nx][ny] = cur;
        qu.push({nx, ny});
      }
    }
  }
  return ans[cur] = tol;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  while (k--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (!vis[a][b])
      printf("%d\n", bfs(a, b));
    else
      printf("%d\n", ans[vis[a][b]]);
  }
  return 0;
}
