#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int n, m, k;
int comp_num = 0;
char v[1005][1005];
int matrix[1005][1005];
int vis[1005][1005];
int ans[100005];
bool ok(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
int dfs(int x, int y) {
  int a, b;
  int res = 0;
  vis[x][y] = 1;
  matrix[x][y] = comp_num;
  for (int i = 0; i < 4; i++) {
    a = x + dx[i];
    b = y + dy[i];
    if (ok(a, b) && v[a][b] == '*') {
      res++;
    } else if (ok(a, b) && v[a][b] == '.' && !vis[a][b]) {
      res += dfs(a, b);
    }
  }
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (int(i) = 0; i < (n); i++) {
    for (int(x) = 0; x < (m); x++) cin >> v[i][x];
  }
  for (int(i) = 0; i < (n); i++) {
    for (int(x) = 0; x < (m); x++) {
      if (v[i][x] == '.') {
        if (vis[i][x]) {
          continue;
        }
        comp_num++;
        ans[comp_num] = dfs(i, x);
      }
    }
  }
  ans[0] = 0;
  int a, b;
  while (k--) {
    cin >> a >> b;
    a--;
    b--;
    cout << ans[matrix[a][b]] << "\n";
  }
}
