#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int maxn = 3000 + 10;
int a[maxn][maxn];
int f[maxn][maxn];
int dis[maxn][maxn];
int vis[maxn][maxn];
const int INF = 1e18;
string b[maxn];
const int dx[] = {0,1,-1,0,0};
const int dy[] = {0,0,0,1,-1};
struct node{
int x,y,t;
friend bool operator < (const node & a,const node & b)
{
return a.t > b.t;
}
};
void solve()
{
int n,m,k;
cin>>n>>m>>k;
int x1,y1;
for(int i=1;i<=k;i++){
int x,y;
cin>>x>>y;
a[x][y] = k - i;
if(i == 1){
x1 = x,y1 = y;
}
}
for(int i=1;i<=n;i++){
cin>>b[i];
b[i] = ' ' + b[i];
}
priority_queue<node>q;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
dis[i][j] = INF;
}
q.push({x1,y1,0});
dis[x1][y1] = 0;
while(!q.empty()){
node top = q.top();
q.pop();
if(vis[top.x][top.y])continue;
vis[top.x][top.y] = 1;
for(int k=1;k<=4;k++){
int nx = top.x + dx[k];
int ny = top.y + dy[k];
if(nx < 1 || nx > n || ny < 1 || ny > m)continue;
if(b[nx][ny] == '#')continue;
if(vis[nx][ny])continue;
int nt = max(a[nx][ny]+1,top.t + 1);
if(nt < dis[nx][ny]){
dis[nx][ny] = nt;
q.push({nx,ny,nt});
}
}
}
int ans = 0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(dis[i][j] == INF)continue;
// cerr<<dis[i][j]<<"\n";
ans += dis[i][j] * dis[i][j];
}
cout<<ans;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while(t--){
solve();
}
return 0;
}