#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long l, long long r) {
  if (r == 0) return 1;
  long long res = bigmod(l, r / 2);
  res = (res * res) % 998244353;
  if (r & 1) res = (res * l) % 998244353;
  return res;
}
string s[1001];
int dis[1001][1001];
bool mark[1001][1001] = {false};
int n, m, mx;
void dfs(int i, int j) {
  if (i >= n || i < 0 || j >= m || j < 0) return;
  if (s[i][j] == '*') {
    mark[i][j] = true;
    mx++;
    return;
  }
  if (mark[i][j]) return;
  mark[i][j] = true;
  dfs(i + 1, j);
  dfs(i, j + 1);
  dfs(i - 1, j);
  dfs(i, j - 1);
  return;
}
void dfs1(int i, int j) {
  if (i >= n || i < 0 || j >= m || j < 0) return;
  if (dis[i][j] != 0) return;
  dis[i][j] = mx;
  if (s[i][j] == '*') {
    return;
  }
  dis[i][j] = mx;
  dfs1(i + 1, j);
  dfs1(i, j + 1);
  dfs1(i - 1, j);
  dfs1(i, j - 1);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, k, t, q = 0, l = 0, p;
  cin >> n >> m >> k;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < k; i++) {
    cin >> j >> l;
    j--;
    l--;
    mx = 0;
    if (!mark[j][l]) {
      dfs(j, l);
      dfs1(j, l);
    }
    cout << dis[j][l] << endl;
  }
  return 0;
}
