#include <bits/stdc++.h>
using namespace std;
const int mxi = 1050;
const int mod = 1e9;
int n, m, k, b[mxi][mxi], ans, seen[mxi][mxi], q, w;
char c;
bool mar[mxi][mxi];
vector<pair<int, int>> v;
void dfs(int x, int y);
void check(int x, int y) {
  if (mar[x][y] == 1) return;
  if (b[x][y] == 1)
    ans++;
  else if ((x > 0 && x <= n) || (y > 0 && y <= m))
    dfs(x, y);
}
void dfs(int x, int y) {
  v.push_back(make_pair(x, y));
  mar[x][y] = 1;
  check(x, y + 1);
  check(x + 1, y);
  check(x - 1, y);
  check(x, y - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c;
      if (c == '.')
        b[i][j] = 0;
      else
        b[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mar[i][j] == 1) continue;
      if (b[i][j] == 1) continue;
      v.clear();
      ans = 0;
      dfs(i, j);
      for (int t = 0; t < v.size(); t++) seen[v[t].first][v[t].second] = ans;
    }
  }
  for (int i = 0; i < k; i++) {
    cin >> q >> w;
    cout << seen[q][w] << "\n";
  }
}
