#include <bits/stdc++.h>
using namespace std;
int n, m, k;
string s[1001];
int x, y;
vector<int> ans;
int was[1001][1001], it;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool ok(int x, int y) { return x > -1 && x < n && y > -1 && y < m; }
int dfs(int x, int y) {
  was[x][y] = it;
  int res = 0;
  for (int i = 0; i < 4; ++i) {
    int ni = x + dx[i];
    int nj = y + dy[i];
    if (ok(ni, nj) && s[ni][nj] == '.' && !was[ni][nj]) {
      res += dfs(ni, nj);
    } else if (ok(ni, nj) && s[ni][nj] == '*')
      ++res;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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 (!was[i][j] && s[i][j] == '.') {
        ++it;
        ans.push_back(dfs(i, j));
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    cin >> x >> y;
    --x;
    --y;
    cout << ans[was[x][y] - 1] << '\n';
  }
  return 0;
}
