#include <bits/stdc++.h>
using namespace std;
int m, n, k, vis1[1005][1005], vis2[1005][1005], pic[1005][1005], cnt;
char s[1005][1005];
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
void bfs1(int a, int b, int flg) {
  vis1[a][b] = 1;
  if (flg) pic[a][b] = flg;
  queue<pair<int, int> > q;
  q.push(make_pair(a, b));
  while (!q.empty()) {
    int ux = q.front().first;
    int uy = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int r = ux + fx[i];
      int c = uy + fy[i];
      if (r >= 0 && r < m && c >= 0 && c < n && s[r][c] == '*') {
        cnt++;
        continue;
      }
      if (r >= 0 && r < m && c >= 0 && c < n && s[r][c] == '.' && !vis1[r][c]) {
        vis1[r][c] = 1;
        q.push(make_pair(r, c));
        if (flg) pic[r][c] = flg;
      }
    }
  }
}
void bfs2(int a, int b, int flg) {
  vis2[a][b] = 1;
  if (flg) pic[a][b] = flg;
  queue<pair<int, int> > q;
  q.push(make_pair(a, b));
  while (!q.empty()) {
    int ux = q.front().first;
    int uy = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int r = ux + fx[i];
      int c = uy + fy[i];
      if (r >= 0 && r < m && c >= 0 && c < n && s[r][c] == '*') {
        cnt++;
        continue;
      }
      if (r >= 0 && r < m && c >= 0 && c < n && s[r][c] == '.' && !vis2[r][c]) {
        vis2[r][c] = 1;
        q.push(make_pair(r, c));
        if (flg) pic[r][c] = flg;
      }
    }
  }
}
int main() {
  int x, y;
  scanf("%d%d%d", &m, &n, &k);
  for (int i = 0; i < m; i++) scanf("%s", &s[i]);
  memset(pic, -1, sizeof(pic));
  memset(vis2, 0, sizeof(vis2));
  memset(vis1, 0, sizeof(vis1));
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    if (pic[x - 1][y - 1] == -1) {
      cnt = 0;
      bfs1(x - 1, y - 1, 0);
      cout << cnt << endl;
      bfs2(x - 1, y - 1, cnt);
    } else
      cout << pic[x - 1][y - 1] << endl;
  }
}
