#include <bits/stdc++.h>
const int max = 1e5 + 10;
using namespace std;
int count1, n, m, k;
pair<int, int> pp;
stack<pair<int, int> > ss;
bool vis[1005][1005];
int ax[4] = {0, 0, 1, -1};
int ay[4] = {1, -1, 0, 0};
char a[1005][1005];
int dfs1[1005][1005];
using namespace std;
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++)
    if (a[x + ax[i]][y + ay[i]] == '*') count1++;
  for (int i = 0; i < 4; i++)
    if (!vis[x + ax[i]][y + ay[i]] && a[x + ax[i]][y + ay[i]] == '.') {
      dfs(x + ax[i], y + ay[i]);
      pp.first = x + ax[i];
      pp.second = y + ay[i];
      ss.push(pp);
    }
}
int main() {
  cin >> n >> m >> k;
  pair<int, int> pp;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      count1 = 0;
      if (!vis[i][j] && a[i][j] == '.') {
        dfs(i, j);
        dfs1[i][j] = count1;
      }
      while (!ss.empty()) {
        pp = ss.top();
        ss.pop();
        dfs1[pp.first][pp.second] = count1;
      }
    }
  while (k--) {
    int x, y;
    count1 = 0;
    cin >> x >> y;
    cout << dfs1[x][y] << endl;
  }
}
