#include <bits/stdc++.h>
using namespace std;
long long sqr(long long a) { return a * a; }
vector<string> second;
int sz = 0;
int n, m;
bool ok(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }
int const dx[] = {0, 0, 1, -1};
int const dy[] = {1, -1, 0, 0};
vector<vector<int> > ans;
vector<vector<bool> > used, u;
void dfs(int x, int y) {
  used[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (ok(xx, yy) && !used[xx][yy]) {
      if (second[xx][yy] == '.') {
        dfs(xx, yy);
      } else {
        sz++;
      }
    }
  }
}
void mark(int x, int y) {
  u[x][y] = 1;
  ans[x][y] = sz;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (ok(xx, yy) && !u[xx][yy] && second[xx][yy] == '.') {
      mark(xx, yy);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int q;
  cin >> n >> m >> q;
  second.resize(n);
  used.resize(n, vector<bool>(m));
  u.resize(n, vector<bool>(m));
  ans.resize(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> second[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!used[i][j] && second[i][j] == '.') {
        sz = 0;
        dfs(i, j);
        mark(i, j);
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    cout << ans[--x][--y] << "\n";
  }
}
