#include <bits/stdc++.h>
using namespace std;
const int BRANCO = -1;
const int CINZA = 0;
const int PRETO = 1;
class Vertice {
 public:
  int id;
  int cor;
  int quadros;
};
void DFSvisit(int &c, int ux, int uy, vector<vector<Vertice> > &verts,
              vector<vector<pair<int, int> > > &adj, vector<Vertice *> &finds) {
  int id = verts[ux][uy].id;
  finds.push_back(&verts[ux][uy]);
  verts[ux][uy].cor = CINZA;
  for (int i = 0; i < adj[id].size(); i++) {
    int vx = adj[id][i].first;
    int vy = adj[id][i].second;
    if (verts[vx][vy].cor == BRANCO) {
      DFSvisit(c, vx, vy, verts, adj, finds);
    }
  }
  c += (4 - adj[id].size());
  verts[ux][uy].cor = PRETO;
}
int ConnectCheck(int &ux, int &uy, vector<vector<Vertice> > &verts,
                 vector<vector<pair<int, int> > > &adj) {
  int c = 0;
  vector<Vertice *> finds;
  if (verts[ux][uy].cor == PRETO) {
    return verts[ux][uy].quadros;
  } else if (verts[ux][uy].cor == BRANCO) {
    DFSvisit(c, ux, uy, verts, adj, finds);
    for (int i = 0; i < finds.size(); i++) {
      Vertice *v = finds.at(i);
      v->quadros = c;
    }
    return c;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, k, quadros, contador;
  string line;
  vector<vector<char> > pixelArt;
  vector<vector<Vertice> > mapaVertices;
  vector<vector<pair<int, int> > > listAdj;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> line;
    vector<char> pixelLine(line.begin(), line.end());
    pixelArt.push_back(pixelLine);
  }
  contador = 0;
  for (int i = 0; i < n; i++) {
    mapaVertices.push_back(vector<Vertice>());
    for (int j = 0; j < m; j++) {
      Vertice vert;
      if (pixelArt[i][j] == '.') {
        vert.id = contador;
        vert.cor = BRANCO;
        vector<pair<int, int> > adjas;
        if (i - 1 >= 0 && pixelArt[i - 1][j] == '.') {
          adjas.push_back(make_pair(i - 1, j));
        }
        if (j - 1 >= 0 && pixelArt[i][j - 1] == '.') {
          adjas.push_back(make_pair(i, j - 1));
        }
        if (j + 1 < m && pixelArt[i][j + 1] == '.') {
          adjas.push_back(make_pair(i, j + 1));
        }
        if (i + 1 < n && pixelArt[i + 1][j] == '.') {
          adjas.push_back(make_pair(i + 1, j));
        }
        listAdj.push_back(adjas);
        contador++;
      } else {
        vert.id = -1;
      }
      mapaVertices[i].push_back(vert);
    }
  }
  for (int i = 1; i <= k; ++i) {
    int x, y;
    cin >> x >> y;
    x -= 1;
    y -= 1;
    quadros = ConnectCheck(x, y, mapaVertices, listAdj);
    cout << quadros << "\n";
  }
  return 0;
}
