#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
int n,m,k;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
char museum[1007][1007];
bool visited[1007][1007];
long long pic;
long long int dp[1007][1007];
vector<p> connected;
void dfs(int x, int y){
if(dp[x][y]!=-1){
pic = dp[x][y];
//cout<<"Hurray"<<endl;
return;
}
if(!visited[x][y] && museum[x][y] == '.'){
//cout<<x<<" "<<y<<endl;
connected.push_back(make_pair(x,y));
visited[x][y] = true;
for(int k=0; k<4; k++){
int nextX = x + dx[k];
int nextY = y + dy[k];
if(museum[nextX][nextY]=='*')
pic++;
if(nextX>0 && nextX<=n && nextY>0 && nextY<=m){
dfs(nextX,nextY);
}
}
}
}
int main(){
cin>>n>>m>>k;
for(int i=0; i<1007; i++){
for(int j=0; j<1007; j++){
dp[i][j] = -1;
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin>>museum[i][j];
}
}
long long ans = 0;
for(int i=0; i<k; i++){
connected.clear();
for(int j=1; j<=n; j++){
for(int z = 1; z<=m; z++)
visited[j][z] = false;
}
int x,y;
cin>>x>>y;
pic = 0;
dfs(x,y);
//cout<<"Done until here"<<endl;
for(int j=0; j<connected.size(); j++){
dp[connected[j].first][connected[j].second] = pic;
}
cout<<pic<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBwYWlyPGludCxpbnQ+IHA7CgkKaW50IG4sbSxrOwoKaW50IGR4WzRdID0gezEsLTEsMCwwfTsKaW50IGR5WzRdID0gezAsMCwxLC0xfTsKCmNoYXIgbXVzZXVtWzEwMDddWzEwMDddOwpib29sIHZpc2l0ZWRbMTAwN11bMTAwN107Cgpsb25nIGxvbmcgcGljOwoKbG9uZyBsb25nIGludCBkcFsxMDA3XVsxMDA3XTsKCnZlY3RvcjxwPiBjb25uZWN0ZWQ7Cgp2b2lkIGRmcyhpbnQg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