#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define int ull
#define endl "\n"
int nt[4][2] = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}
};
void solve(){
int n, m, k;
cin >> n >> m >> k;
map<pair<int, int>, int> mp;
int i;
int nowx1 = -1, nowy1 = -1;
int nowx2 = -1, nowy2 = -1;
for(i = 0 ; i < k ; i ++) {
int x, y;
cin >> x >> y;
x--;
y--;
if(i == 0) {
nowx1 = x;
nowy1 = y;
}
if(i == 1) {
nowx2 = x;
nowy2 = y;
}
if(i != 0) mp[{x, y}] = k - i;
}
vector<vector<int>> f1(n + 3, vector<int>(m + 3, 1e18)), f2(n + 3, vector<int>(m + 3, 1e18));
vector<vector<int>> book(n + 3, vector<int>(m + 3, 0));
vector<string> a(n + 3);
int j;
for(i = 0 ; i < n ; i ++) {
cin >> a[i];
}
queue<array<int, 3>> q;
q.push({nowx1, nowy1, 0});
while(!q.empty()) {
auto it = q.front();
q.pop();
int x = it[0], y = it[1], step = it[2];
if(x < 0 || y < 0 || x >= n || y >= m) continue;
if(a[x][y] == '#') continue;
f1[x][y] = min(f1[x][y], step);
if(mp.find({x, y}) != mp.end()) {
f1[x][y] = max(mp[{x, y}], f1[x][y]);
}
if(book[x][y]) continue;
book[x][y] = 1;
for(i = 0 ; i < 4 ; i ++) {
int nx = x + nt[i][0], ny = y + nt[i][1];
q.push({nx, ny, f1[x][y] + 1});
}
}
for(i = 0 ; i <= n ; i ++) {
for(j = 0 ; j <= m ; j ++) book[i][j] = 0;
}
q.push({nowx2, nowy2, k - 1});
while(!q.empty()) {
auto it = q.front();
q.pop();
int x = it[0], y = it[1], step = it[2];
if(x < 0 || y < 0 || x >= n || y >= m) continue;
if(a[x][y] == '#') continue;
f2[x][y] = min(f2[x][y], step);
if(book[x][y]) continue;
book[x][y] = 1;
for(i = 0 ; i < 4 ; i ++) {
int nx = x + nt[i][0], ny = y + nt[i][1];
q.push({nx, ny, f2[x][y] + 1});
}
}
ull ans = 0;
for(i = 0 ; i < n ; i ++) {
for(j = 0 ; j < m ; j ++) {
f1[i][j] = min(f1[i][j], f2[i][j]);
if(f1[i][j] == 1e18) continue;
ans += f1[i][j] * f1[i][j];
// cout << f1[i][j] << ' ';
}
// cout << endl;
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}