#include <bits/stdc++.h>
char g[1000][1000];
int visited[1000][1000];
int clique[1000][1000];
int ans[1000000];
int ccount = 0;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int k;
  std::cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    for (int j = 0; j < m; ++j) {
      g[i][j] = s[j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == '*') continue;
      if (visited[i][j]) continue;
      int st = 0;
      std::queue<std::pair<int, int>> Q;
      Q.push(std::make_pair(i, j));
      ccount++;
      visited[i][j] = 1 + i * m + j;
      while (!Q.empty()) {
        auto v = Q.front();
        Q.pop();
        int x = v.first;
        int y = v.second;
        clique[x][y] = ccount;
        for (int ii = 0; ii < 4; ++ii) {
          int nx = x + dx[ii];
          int ny = y + dy[ii];
          if (nx < 0 || ny < 0) continue;
          if (nx >= n || ny >= m) continue;
          if (visited[nx][ny] == 1 + i * m + j) {
            continue;
          }
          if (g[nx][ny] == '.') {
            Q.push(std::make_pair(nx, ny));
            visited[nx][ny] = 1 + i * m + j;
          } else {
            st++;
          }
        }
      }
      ans[ccount] = st;
    }
  }
  for (int i = 0; i < k; ++i) {
    int x, y;
    std::cin >> x >> y;
    x--;
    y--;
    std::cout << ans[clique[x][y]] << '\n';
  }
  return 0;
}
