#include <bits/stdc++.h>
using namespace std;
char A[1000][1000];
int n, m;
vector<pair<int, int> > B[1000][1000];
int visited[1000][1000];
vector<pair<int, int> > C;
int D[1000][1000];
long long int sum = 0;
long long int MOD(long long int a, long long int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
int max3(int a, int b, int c) { return max(c, max(a, b)); }
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int logg(long long int a) {
  long long int x = 0;
  while (a > 1) {
    x++;
    a /= 2;
  }
  return x;
}
void dfs(int i, int j) {
  visited[i][j] = 1;
  C.push_back(make_pair(i, j));
  if (i - 1 >= 0) {
    if (A[i - 1][j] == '*') sum++;
  }
  if (j - 1 >= 0) {
    if (A[i][j - 1] == '*') sum++;
  }
  if (i + 1 < n) {
    if (A[i + 1][j] == '*') sum++;
  }
  if (j + 1 < m) {
    if (A[i][j + 1] == '*') sum++;
  }
  for (int l = 0; l < B[i][j].size(); l++) {
    if (!visited[B[i][j][l].first][B[i][j][l].second])
      dfs(B[i][j][l].first, B[i][j][l].second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> A[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (A[i][j] == '*') continue;
      if (i - 1 >= 0) {
        if (A[i - 1][j] == '.') B[i][j].push_back(make_pair(i - 1, j));
      }
      if (j - 1 >= 0) {
        if (A[i][j - 1] == '.') B[i][j].push_back(make_pair(i, j - 1));
      }
      if (i + 1 < n) {
        if (A[i + 1][j] == '.') B[i][j].push_back(make_pair(i + 1, j));
      }
      if (j + 1 < m) {
        if (A[i][j + 1] == '.') B[i][j].push_back(make_pair(i, j + 1));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) visited[i][j] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (A[i][j] == '.') {
        sum = 0;
        C.clear();
        if (!visited[i][j]) {
          dfs(i, j);
          for (int l = 0; l < C.size(); l++) D[C[l].first][C[l].second] = sum;
        }
      }
    }
  }
  while (k--) {
    int x, y;
    cin >> x >> y;
    cout << D[x - 1][y - 1] << endl;
  }
}
