#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int MXN = 1005;
string s[MXN];
int vis[MXN][MXN];
pair<int, int> parent[MXN][MXN];
int cnts[MXN][MXN];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void dfs(int i, int j, int pi, int pj) {
  if (i < 0 || j < 0 || i >= n || j >= m) return;
  if (vis[i][j]) return;
  if (s[i][j] == '*') {
    cnts[pi][pj]++;
    return;
  }
  vis[i][j] = 1;
  parent[i][j] = make_pair(pi, pj);
  for (int x = 0; x < 4; x++) {
    dfs(i + dx[x], j + dy[x], pi, pj);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.' && !vis[i][j]) dfs(i, j, i, j);
    }
  }
  for (int x = 0; x < k; x++) {
    int i, j;
    cin >> i >> j;
    i--;
    j--;
    pair<int, int> p = parent[i][j];
    cout << cnts[p.first][p.second] << endl;
  }
  return 0;
}
