#include <bits/stdc++.h>
using namespace std;
long long int fact(long long int n) {
  if (n == 1 || n == 0) return 1;
  return n * fact(n - 1);
}
long long int isPrime(long long int n) {
  if (n < 2) return 0;
  if (n < 4) return 1;
  if (n % 2 == 0 or n % 3 == 0) return 0;
  for (long long int i = 5; i * i <= n; i += 6)
    if (n % i == 0 or n % (i + 2) == 0) return 0;
  return 1;
}
long long int modexpo(long long int x, long long int p) {
  long long int res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
long long int binSearch(long long int a[], long long int l, long long int h,
                        long long int x) {
  long long int c = -1;
  while (l <= h) {
    long long int m = (l + h) / 2;
    if (a[m] >= x) {
      c = m;
      h = m - 1;
    } else
      l = m + 1;
  }
  return c;
}
void pairsort(long long int a[], long long int b[], long long int n) {
  pair<long long int, long long int> pairt[n];
  for (long long int i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (long long int i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
long long int nod(long long int n) {
  long long int c = 0;
  while (n > 0) {
    c++;
    n /= 10;
  }
  return c;
}
long long int sod(long long int n) {
  long long int s = 0;
  while (n > 0) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
long long int mulmod(long long int a, long long int b) {
  long long int res = 0;
  a = a % 1000000007;
  while (b > 0) {
    if (b % 2 == 1) res = (res + a) % 1000000007;
    a = (a * 2) % 1000000007;
    b /= 2;
  }
  return res % 1000000007;
}
string intToString(long long int n) {
  string s = "";
  while (n > 0) {
    s += char(n % 10 + '0');
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
string s[1005];
long long int vis[1005][1005], val[1005][1005], cnt[1005][1005], n, m;
void bfs(long long int x, long long int y) {
  long long int i;
  long long int tot = 0;
  vis[x][y] = 1;
  queue<pair<long long int, long long int>> q;
  std::vector<pair<long long int, long long int>> v;
  q.push({x, y});
  v.push_back({x, y});
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    tot += val[x][y];
    if (x > 0 && s[x - 1][y] == '.' && !vis[x - 1][y]) {
      vis[x - 1][y] = 1;
      q.push({x - 1, y});
      v.push_back({x - 1, y});
    }
    if (y > 0 && s[x][y - 1] == '.' && !vis[x][y - 1]) {
      vis[x][y - 1] = 1;
      q.push({x, y - 1});
      v.push_back({x, y - 1});
    }
    if (x < n - 1 && s[x + 1][y] == '.' && !vis[x + 1][y]) {
      vis[x + 1][y] = 1;
      q.push({x + 1, y});
      v.push_back({x + 1, y});
    }
    if (y < m - 1 && s[x][y + 1] == '.' && !vis[x][y + 1]) {
      vis[x][y + 1] = 1;
      q.push({x, y + 1});
      v.push_back({x, y + 1});
    }
  }
  for (i = 0; i < v.size(); i++) {
    cnt[v[i].first][v[i].second] = tot;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int q, t, k = 1, i, j, f = 0, g = 0, h = 1, sum = 0, ans = 0, x, y,
                      l, r;
  cin >> n >> m >> k;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (x = 0; x < n; x++) {
    for (y = 0; y < m; y++) {
      if (s[x][y] == '*') continue;
      if (x > 0 && s[x - 1][y] == '*') val[x][y]++;
      if (y > 0 && s[x][y - 1] == '*') val[x][y]++;
      if (x < n - 1 && s[x + 1][y] == '*') val[x][y]++;
      if (y < m - 1 && s[x][y + 1] == '*') val[x][y]++;
    }
  }
  for (x = 0; x < n; x++) {
    for (y = 0; y < m; y++) {
      if (!vis[x][y] && s[x][y] == '.') {
        bfs(x, y);
      }
    }
  }
  for (i = 0; i < k; i++) {
    cin >> f >> g;
    cout << cnt[f - 1][g - 1] << endl;
  }
  return 0;
}
