#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = int(1e9);
const int MAX = 1111;
string grid[MAX];
int n, m, k, res;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool visited[MAX][MAX];
int dp[MAX][MAX];
vector<pair<int, int> > comp;
bool isValid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
void dfs(int x, int y) {
  if (visited[x][y]) {
    return;
  }
  visited[x][y] = true;
  comp.push_back(pair<int, int>(x, y));
  for (int dir = 0; dir < 4; dir++) {
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (isValid(nx, ny)) {
      if (grid[nx][ny] == '*') {
        res++;
      } else if (grid[nx][ny] == '.') {
        dfs(nx, ny);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!visited[i][j] && grid[i][j] == '.') {
        dfs(i, j);
        for (auto p : comp) {
          dp[p.first][p.second] = res;
        }
        comp.clear();
        res = 0;
      }
    }
  }
  for (int i = 0; i < k; i++) {
    res = 0;
    int sx, sy;
    cin >> sx >> sy;
    sx--;
    sy--;
    cout << dp[sx][sy] << "\n";
  }
  return 0;
}
