#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define int unsigned long long
#define INF 0x3f3f3f3f
#define LNF (ll) 0x3f3f3f3f3f3f3f3f
#define MOD (int) (1e9+7)
#define N 3030
int dis[N][N], vis[N][N], enq[N], sg[N][N], g[N][N];
pair<int, int> snake[N];
int vec[5] = { 0, 1, 0, -1, 0 };
signed main() {
#ifdef TEST
freopen("zz.in", "r+", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k; cin >> n >> m >> k;
for (int i = 1; i <= k; ++ i) {
cin >> snake[i].first >> snake[i].second;
sg[snake[i].first][snake[i].second] = i;
}
for (int i = 1; i <= n; ++ i) {
string s; cin >> s;
for (int j = 1; j <= m; ++ j) {
g[i][j] = s[j-1] == '.' ? 1 : 0;
}
}
int d = 0;
queue<pair<int, int>> bfsq;
auto [hx, hy] = snake[1];
bfsq.push(pair<int, int>(hx, hy));
vis[hx][hy] = 1;
dis[hx][hy] = d;
while (!bfsq.empty() || d <= k+10) {
int ck = k - d + 1;
if (ck > 1 && ck <= k && enq[ck]) {
auto [cx, cy] = snake[ck];
assert(!vis[cx][cy]);
bfsq.push(pair<int, int>(cx, cy));
vis[cx][cy] = 1;
dis[cx][cy] = d;
}
int sz = bfsq.size();
++ d;
while (sz --) {
auto [tx, ty] = bfsq.front(); bfsq.pop();
for (int i = 0; i < 4; ++ i) {
int nx = tx + vec[i], ny = ty + vec[i+1];
if (nx < 1 || ny < 1 || nx > n || ny > m) continue;
if (!g[nx][ny]) continue;
if (vis[nx][ny]) continue;
if (sg[nx][ny] != 0 && d < k - sg[nx][ny] + 1) {
enq[sg[nx][ny]] = 1;
continue;
} else if (sg[nx][ny] != 0) {
enq[sg[nx][ny]] = 0;
}
bfsq.push(pair<int, int>(nx, ny));
vis[nx][ny] = 1;
dis[nx][ny] = d;
}
}
}
ll res = 0;
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
res += 1ll * dis[i][j] * dis[i][j];
}
}
cout << res << '\n';
}
// k-i+1 == d
// i = k-d