#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1002;
bool a[N][N];
bool used[N][N];
int b[N][N];
int cnt = 0;
int id = 0;
vector<int> is;
void dfs(int x, int y) {
  used[x][y] = true;
  b[x][y] = id;
  if (a[x + 1][y] && !used[x + 1][y])
    dfs(x + 1, y);
  else if (!a[x + 1][y])
    cnt++;
  if (a[x - 1][y] && !used[x - 1][y])
    dfs(x - 1, y);
  else if (!a[x - 1][y])
    cnt++;
  if (a[x][y + 1] && !used[x][y + 1])
    dfs(x, y + 1);
  else if (!a[x][y + 1])
    cnt++;
  if (a[x][y - 1] && !used[x][y - 1])
    dfs(x, y - 1);
  else if (!a[x][y - 1])
    cnt++;
}
void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char x;
      cin >> x;
      if (x == '.') a[i][j] = true;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (used[i][j] || !a[i][j]) continue;
      cnt = 0;
      dfs(i, j);
      is.push_back(cnt);
      id++;
    }
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    cout << is[b[x][y]] << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
}
