#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
ll Mod = 1e9 + 7;
ll INF = 0x3f3f3f3f;
ll gra[3005][3005] = { 0 }; //地图
ll qd[3005][3005] = { 0 }; //是否确定
ll snake[3005][3005] = { 0 }; //蛇身
ll dis[3005][3005] = { INF }; //距离
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };
struct dian {
ll x, y, di;
};
inline bool operator < (dian A, dian B) { return A.di > B.di; }
priority_queue<dian>que;
void solve()
{
ll n, m, k, res = 0; cin >> n >> m >> k;
for (ll i = 1; i <= k; ++i) {
ll x, y; cin >> x >> y;
snake[x][y] = 1;
if (i != 1)dis[x][y] = k - i + 1;
else { que.push({ x,y,0 }); qd[x][y] = 1; }
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 1; j <= m; ++j) {
char ch; cin >> ch;
if (ch == '.') { gra[i][j] = 1; }
}
}
while (!que.empty()) {
dian di = que.top(); que.pop();
ll x = di.x, y = di.y, d = di.di;
//cout << x << " " << y << " " << d << endl;
for (int i = 0; i < 4; ++i) {
ll nx = x + dx[i], ny = y + dy[i];
if (nx<1 || nx>n || ny<1 || ny>m)continue;
if (gra[nx][ny] == 0 || qd[nx][ny])continue;
if (snake[nx][ny] == 0) {
dis[nx][ny] = d + 1;
que.push({ nx,ny,d + 1 });
qd[nx][ny] = 1;
}
else {
dis[nx][ny] = max(dis[nx][ny], d + 1);
que.push({ nx,ny,dis[nx][ny] });
qd[nx][ny] = 1;
}
}
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 1; j <= m; ++j) {
if (dis[i][j] != INF) { res += dis[i][j] * dis[i][j]; }
}
}
cout << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1; //cin >> t;
while (t--) { solve(); }
return 0;
}