#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long sqr(long long x) { return x * x; }
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <class T>
inline void chmax(T &x, T y) {
  x = max((x), (y));
}
template <class T>
inline void chmin(T &x, T y) {
  x = min((x), (y));
}
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T powm(T a, T b, long long m) {
  T cnt = 1;
  while (b > 0) {
    if (b % 2 == 1) cnt = (cnt * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return cnt % m;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  if (r > n) return 0;
  if (r > n - r) r = n - r;
  for (long long i = 0; i < r; i++) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
const int MOD = 1000000007;
const int N = 1005;
void prec() {}
int n, m, k, tot;
int dp[N][N], vis[N][N];
char a[N][N];
vector<pair<int, int> > v;
void dfs(int i, int j) {
  if (i < 1 || j < 1 || i > n || j > m || vis[i][j]) return;
  if (a[i][j] == '*') {
    tot++;
    return;
  }
  vis[i][j] = 1;
  v.push_back(make_pair(i, j));
  for (int k = 0; k < 4; k++) dfs(i + dx[k], j + dy[k]);
}
void run() {
  cin >> n >> m >> k;
  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++) {
      if (a[i][j] == '.' && !vis[i][j]) {
        v.clear();
        tot = 0;
        dfs(i, j);
        for (auto it : v) dp[it.first][it.second] = tot;
      }
    }
  }
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    cout << dp[x][y] << "\n";
  }
}
int32_t main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int tc = 1;
  prec();
  for (long long i = 0; i < tc; ++i) run();
  return 0;
}
