#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
const long long int inf = 1e18;
long long int n, m, ans = 0;
vector<long long int> dx{0, 0, 1, -1};
vector<long long int> dy{1, -1, 0, 0};
bool isvalid(vector<string>& a, vector<vector<bool>>& vis, long long int x,
             long long int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == '*' || vis[x][y] == true)
    return false;
  return true;
}
void dfs(vector<string>& a, vector<vector<bool>>& vis, long long int x,
         long long int y,
         vector<vector<pair<long long int, long long int>>>& store,
         long long int ans_x, long long int ans_y) {
  vis[x][y] = 1;
  for (long long int i = 0; i < 4; i++) {
    if (isvalid(a, vis, x + dx[i], y + dy[i])) {
      dfs(a, vis, x + dx[i], y + dy[i], store, ans_x, ans_y);
    } else if (a[x + dx[i]][y + dy[i]] == '*') {
      ans++;
    }
  }
  store[x][y] = {ans_x, ans_y};
}
void solve() {
  long long int k;
  cin >> n >> m >> k;
  vector<string> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<bool>> vis(n + 1, vector<bool>(m + 1, false));
  vector<vector<pair<long long int, long long int>>> store(
      n + 1, vector<pair<long long int, long long int>>(m + 1, {0, 0}));
  vector<vector<long long int>> result(n, vector<long long int>(m, 0));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] != '*' and !vis[i][j]) {
        ans = 0;
        dfs(a, vis, i, j, store, i, j);
        result[store[i][j].first][store[i][j].second] = ans;
      }
    }
  }
  while (k--) {
    long long int x, y;
    cin >> x >> y;
    x--, y--;
    cout << result[store[x][y].first][store[x][y].second];
    cout << "\n";
    ;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int q = 1;
  while (q--) {
    solve();
  }
}
