#include <bits/stdc++.h>
using namespace std;
template <typename T>
void make_unique(vector<T> &vec) {
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
void debb(long long int x) { cerr << x; }
void debb(double x) { cerr << x; }
void debb(long double x) { cerr << x; }
void debb(char x) { cerr << '\'' << x << '\''; }
void debb(const char *x) { cerr << '\"' << x << '\"'; }
void debb(const string &x) { cerr << '\"' << x << '\"'; }
void debb(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void debb(const pair<T, V> &x) {
  cerr << '{';
  debb(x.first);
  cerr << ',';
  debb(x.second);
  cerr << '}';
}
template <typename T>
void debb(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), debb(i);
  cerr << "}";
}
void _debb() { cerr << "]\n"; }
template <typename T, typename... V>
void _debb(T t, V... v) {
  debb(t);
  if (sizeof...(v)) cerr << ", ";
  _debb(v...);
}
const long long int mod = 1000000007;
const long double PI = 3.141592653589793;
const long long int inf = 1e15;
const long long int cons = 1005;
long long int N, M, cnt1;
long long int g[cons][cons], vis[cons][cons];
long long int a[cons][cons];
vector<long long int> v;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool isvalid2(long long int x, long long int y) {
  if (x < 1 || x > N || y < 1 || y > M || g[x][y] != 1) return false;
  return true;
}
bool isvalid(long long int x, long long int y) {
  if (x < 1 || x > N || y < 1 || y > M) return false;
  if (vis[x][y] == 1 || g[x][y] == 1) return false;
  return true;
}
long long int dfs(long long int x, long long int y) {
  vis[x][y] = 1;
  a[x][y] = cnt1;
  long long int sum = 0;
  for (long long int i = 0; i < 4; i++) {
    if (isvalid2(x + dx[i], y + dy[i])) {
      sum++;
    }
    if (isvalid(x + dx[i], y + dy[i])) {
      sum += dfs(x + dx[i], y + dy[i]);
    }
  }
  return sum;
}
long long int solve() {}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int n = 0, m = 0, i = 0, j = 0, k = 0, cnt = 0, ans = 0, sum = 0,
                flag = 0, pos = -1, ind = -1, mn = inf, mx = -inf, res = 0;
  cin >> N >> M >> k;
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        g[i + 1][j + 1] = 0;
      } else {
        g[i + 1][j + 1] = 1;
      }
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) {
      if (g[i][j] == 0 && vis[i][j] == 0) {
        long long int h = dfs(i, j);
        v.push_back(h);
        cnt1++;
      }
    }
  }
  for (i = 0; i < k; i++) {
    long long int b, d;
    cin >> b >> d;
    cout << v[a[b][d]] << '\n';
  }
  return 0;
}
