#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;     node(int x1 = 0, int y1 = 0) : x(x1), y(y1){};     bool operator=(const node &b) const { return (x == b.x) && (y == b.y); }   };   const int dx[5] = {0, 0, 0, 1, -1};   const int dy[5] = {0, 1, -1, 0, 0};   int N, M, Q;   char maze[1007][1007];   int ans = 0;   int vis[1007][1007];   int memo[1000007];   void dfs(int x, int y, int id) {     if (maze[x][y] ==  * ) return;     for (int i = 1; i <= 4; i++) {       int x1 = x + dx[i];       int y1 = y + dy[i];       if (x1 > 0 && x1 <= N && y1 > 0 && y1 <= M && maze[x1][y1] ==  * ) ans++;     }     for (int i = 1; i <= 4; i++) {       int x1 = x + dx[i];       int y1 = y + dy[i];       if (maze[x1][y1] ==  .  && vis[x1][y1] == 0 && x1 > 0 && x1 <= N &&           y1 > 0 && y1 <= M) {         vis[x1][y1] = id;         dfs(x1, y1, id);       }     }     return;   }   int main() {     scanf( %d%d%d , &N, &M, &Q);     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         cin >> maze[i][j];       }     }     int k = 1;     while (Q--) {       int x, y;       scanf( %d%d , &x, &y);       if (vis[x][y] == 0) {         ans = 0;         vis[x][y] = k;         dfs(x, y, k);         memo[k] = ans;         k++;       }       printf( %d n , memo[vis[x][y]]);     }     return 0;   }   