#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned long long;
const int N = 3001;
const int M = 3001;
uint dis[N][M];
int ff[4];
int tt[4];
int py[N][M];
int vis[N][M];
struct node{
int x;
int y;
// uint w;
uint step;
int len;
bool operator<(const node& b) const {
return step > b.step;
}
};
char s[N][N];
void solve(){
int n, m, k;
cin >> n >> m >> k;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
py[i][j] = k + 1;
}
}
// vector<vector<int>> py(n + 1, vector<int> (m + 1, k + 1));
int xx, yy;
cin >> xx >> yy;
py[xx][yy] = 1;
for(int i = 2; i <= k; i++){
int a, b;
cin >> a >> b;
py[a][b] = i;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++)
cin >> s[i][j];
}
// vector<vector<uint>> dis(n + 1, vector<uint> (m + 1));
auto bfs = [&](){
priority_queue<node> q;
ff[0] = -1;
ff[1] = 1;
tt[2] = 1;
tt[3] = -1;
// vector<vector<int>> vis(n + 1, vector<int> (m + 1));
q.push({xx, yy, 0, k});
while(!q.empty()){
auto [x, y, step, len] = q.top();
q.pop();
if(vis[x][y])continue;
vis[x][y] = 1;
dis[x][y] = step;
for(int p = 0; p < 4; p++){
int u = x + ff[p];
int v = y + tt[p];
if(u <= n && u >= 1 && v <= m && v >= 1){
if(s[u][v] == '.' && vis[u][v] == 0){
if(py[u][v] + step < len){//py + step 代表现在蛇的位置
int cnt = len - py[u][v] - step;
q.push({u, v, dis[x][y] + cnt + 1, len - cnt});
}
else q.push({u, v, dis[x][y] + 1, len});
}
}
}
}
};
bfs();
uint ans = 0;
// for(int i = 1; i <= n; i++){
// for(int j = 1; j <= m; j++){
// cout << py[i][j] << " ";
// }
// cout << '\n';
// }
// cout << "---------------" << endl;
// for(int i = 1; i <= n; i++){
// for(int j = 1; j <= m; j++){
// cout << dis[i][j] << " ";
// }
// cout << '\n';
// }
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
ans += dis[i][j] * dis[i][j];
}
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}