#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI = acos(-1.0);
template <class T>
inline T _abs(T n) {
  return ((n) < 0 ? -(n) : (n));
}
template <class T>
inline T _max(T a, T b) {
  return (!((a) < (b)) ? (a) : (b));
}
template <class T>
inline T _min(T a, T b) {
  return (((a) < (b)) ? (a) : (b));
}
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int t, n, m, w;
int adj[1005][1005];
string s;
int dirx[] = {0, 0, 1, -1};
int diry[] = {1, -1, 0, 0};
int *dist[1005][1005], val[1005][1005];
bool mark[1005][1005];
int p, q;
bool check(int x, int y) {
  if (x > 0 && x <= n && y > 0 && y <= m) return true;
  return false;
}
void dfs(int srcx, int srcy) {
  mark[srcx][srcy] = 1;
  int posx, posy;
  dist[srcx][srcy] = &val[p][q];
  for (int i = 0; i < (4); i++) {
    posx = srcx + dirx[i];
    posy = diry[i] + srcy;
    if (check(posx, posy) && adj[posx][posy] == 0) val[p][q]++;
    if (check(posx, posy) && mark[posx][posy] == 0 && adj[posx][posy])
      dfs(posx, posy);
  }
}
int main() {
  while (~scanf("%d%d%d", &n, &m, &w)) {
    memset(adj, 0, sizeof(adj));
    for (int i = 1; i <= (n); i++) {
      cin >> s;
      for (int j = 0; j < (m); j++) {
        if (s[j] == '.') adj[i][j + 1] = 1;
      }
    }
    memset(val, 0, sizeof(val));
    memset(mark, 0, sizeof(mark));
    int a, b;
    for (int i = 1; i <= (w); i++) {
      scanf("%d%d", &a, &b);
      if (mark[a][b] == 0) {
        p = a;
        q = b;
        dfs(p, q);
      }
      printf("%d\n", *dist[a][b]);
    }
  }
  return 0;
}
