#include <bits/stdc++.h>
using namespace std;
bool visited[1001][1001] = {false}, v[1001][1001] = {false};
int ans[1001][1001] = {0};
char a[1001][1001];
int n, m, c, k;
void dfs1(int i, int j) {
  visited[i][j] = true;
  if (a[i][j - 1] == '*') c++;
  if (a[i][j + 1] == '*') c++;
  if (a[i - 1][j] == '*') c++;
  if (a[i + 1][j] == '*') c++;
  if (a[i][j - 1] == '.' && visited[i][j - 1] == false) dfs1(i, j - 1);
  if (a[i][j + 1] == '.' && visited[i][j + 1] == false) dfs1(i, j + 1);
  if (a[i - 1][j] == '.' && visited[i - 1][j] == false) dfs1(i - 1, j);
  if (a[i + 1][j] == '.' && visited[i + 1][j] == false) dfs1(i + 1, j);
}
void dfs2(int i, int j) {
  v[i][j] = true;
  ans[i][j] = c;
  if (a[i][j - 1] == '.' && v[i][j - 1] == false) dfs2(i, j - 1);
  if (a[i][j + 1] == '.' && v[i][j + 1] == false) dfs2(i, j + 1);
  if (a[i - 1][j] == '.' && v[i - 1][j] == false) dfs2(i - 1, j);
  if (a[i + 1][j] == '.' && v[i + 1][j] == false) dfs2(i + 1, j);
}
int main() {
  ios::sync_with_stdio(false);
  int i, j, l;
  c = 0;
  cin >> n >> m >> k;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 1; i < n - 1; i++)
    for (j = 1; j < m - 1; j++) {
      if (visited[i][j] == false && a[i][j] == '.') {
        dfs1(i, j);
        dfs2(i, j);
        c = 0;
      }
    }
  while (k--) {
    int x, y;
    cin >> x >> y;
    cout << ans[x - 1][y - 1] << endl;
  }
  return 0;
}
