#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dp[1005][1005];
int vis[1005][1005];
int sx, sy, x, y;
vector<string> v;
bool valid(int xx, int yy) {
  if (xx >= 0 && yy >= 0 && xx < x && yy < y && v[xx][yy] != '*') return 1;
  return 0;
}
int bfs() {
  int wx, wy, ans = 0;
  vector<pair<int, int> > vaa;
  queue<pair<int, int> > q;
  q.push(make_pair(sx, sy));
  vis[sx][sy] = 1;
  while (!q.empty()) {
    sx = q.front().first;
    sy = q.front().second;
    vaa.push_back(make_pair(sx, sy));
    q.pop();
    for (int i = 0; i < 4; i++) {
      wx = sx + dx[i];
      wy = sy + dy[i];
      if (!valid(wx, wy)) ans++;
      if (valid(wx, wy) && !vis[wx][wy]) {
        vis[wx][wy] = 1;
        q.push(pair<int, int>(wx, wy));
      }
    }
  }
  for (int i = 0; i < vaa.size(); i++) dp[vaa[i].first][vaa[i].second] = ans;
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  memset(vis, 0, sizeof(vis));
  int t;
  string s;
  cin >> x >> y >> t;
  for (int i = 0; i < x; i++) {
    cin >> s;
    v.push_back(s);
  }
  while (t--) {
    scanf("%d %d", &sx, &sy);
    sx--;
    sy--;
    if (dp[sx][sy] != -1)
      printf("%d\n", dp[sx][sy]);
    else
      printf("%d\n", bfs());
  }
  return 0;
}
