#include <bits/stdc++.h>
using namespace std;
const int N = 0;
int n, k, x, t, m;
string s;
vector<int> v;
vector<string> grid;
vector<pair<int, int>> stars;
bool vis[1005][1005];
bool vis1[1005][1005];
int cnt[1005][1005];
int xc[] = {1, -1, 0, 0};
int yc[] = {0, 0, 1, -1};
bool check(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int dx = xc[i] + x;
    int dy = yc[i] + y;
    if (!check(dx, dy)) {
      continue;
    }
    if (grid[dx][dy] == '*' && !vis[dx][dy]) {
      cnt[x][y]++;
      continue;
    }
    if (grid[dx][dy] == '.' && !vis[dx][dy]) {
      cnt[x][y] += dfs(dx, dy);
    }
  }
  return cnt[x][y];
}
void dfs1(int x, int y, int count) {
  cnt[x][y] = count;
  vis1[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int dx = xc[i] + x;
    int dy = yc[i] + y;
    if (!check(dx, dy)) {
      continue;
    }
    if (grid[dx][dy] == '*') {
      continue;
    }
    if (check(dx, dy) && grid[dx][dy] == '.' && !vis1[dx][dy]) {
      dfs1(dx, dy, count);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    cin >> s;
    grid.push_back(s);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      vis[i][j] = false;
      vis1[i][j] = false;
      cnt[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vis[i][j]) continue;
      if (grid[i][j] == '.') {
        int cnt = dfs(i, j);
        dfs1(i, j, cnt);
      }
    }
  }
  for (int i = 0, a, b; i < k; i++) {
    cin >> a >> b;
    a--, b--;
    cout << cnt[a][b] << endl;
  }
  return 0;
}
