#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int a[n + 1][m + 1], vis[n + 1][m + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        a[i][j] = 1;
      } else {
        a[i][j] = 0;
      }
      vis[i][j] = 0;
    }
  }
  int dx[4] = {-1, 0, 0, 1};
  int dy[4] = {0, -1, 1, 0};
  int ctr = 1;
  map<int, int> cnt;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 1 && vis[i][j] == 0) {
        vis[i][j] = ctr;
        queue<pair<int, int> > q;
        q.push({i, j});
        while (!q.empty()) {
          int x1 = q.front().first;
          int y1 = q.front().second;
          q.pop();
          for (int z = 0; z < 4; z++) {
            int x = x1 + dx[z];
            int y = y1 + dy[z];
            if (x > 0 && x <= n && y > 0 && y <= m) {
              if (a[x][y] == 1) {
                if (vis[x][y] == 0) {
                  vis[x][y] = ctr;
                  q.push({x, y});
                }
              } else {
                cnt[ctr]++;
              }
            }
          }
        }
        ctr++;
      }
    }
  }
  while (k--) {
    int x, y;
    cin >> x >> y;
    cout << cnt[vis[x][y]] << endl;
  }
}
