#include <bits/stdc++.h>
using namespace std;
char ch[1010][1010];
int n, m, p;
int arr[12];
int ans[12];
int visit[1010][1010];
int dis[1010][1010];
int taken[1010][1010];
int beg[1010][1010];
int kep[1010][1010];
int dx[6] = {0, 1, -1, 0, 0};
int dy[6] = {0, 0, 0, 1, -1};
queue<int> qx[12];
queue<int> qy[12];
int bfs(int plr) {
  vector<int> tx, ty;
  while (qx[plr].size()) {
    tx.push_back(qx[plr].front());
    qx[plr].pop();
    ty.push_back(qy[plr].front());
    qy[plr].pop();
  }
  for (int i = 0; i < tx.size(); i++) {
    int x = tx[i];
    int y = ty[i];
    dis[x][y] = 0;
    qx[plr].push(x);
    qy[plr].push(y);
  }
  tx.clear();
  ty.clear();
  int f = 0;
  while (qx[plr].size()) {
    int u = qx[plr].front();
    int v = qy[plr].front();
    qx[plr].pop();
    qy[plr].pop();
    if (dis[u][v] == arr[plr]) {
      f = 1;
      tx.push_back(u);
      ty.push_back(v);
      continue;
    }
    for (int i = 1; i <= 4; i++) {
      int x = u + dx[i];
      int y = v + dy[i];
      if (x < 1 || x > n) continue;
      if (y < 1 || y > m) continue;
      if (taken[x][y] || ch[x][y] == '#') continue;
      taken[x][y] = 1;
      dis[x][y] = dis[u][v] + 1;
      ans[plr]++;
      qx[plr].push(x);
      qy[plr].push(y);
    }
  }
  while (qx[plr].size()) {
    qx[plr].pop();
    qy[plr].pop();
  }
  for (int i = 0; i < tx.size(); i++) {
    int x = tx[i];
    int y = ty[i];
    qx[plr].push(x);
    qy[plr].push(y);
  }
  return f;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (ch[i][j] == '.' || ch[i][j] == '#') continue;
      int plr = ch[i][j] - '0';
      visit[i][j] = plr;
      qx[plr].push(i);
      qy[plr].push(j);
      taken[i][j] = 1;
      ans[plr]++;
    }
  }
  while (1) {
    int uu = 0;
    for (int i = 1; i <= p; i++) {
      uu = uu | bfs(i);
    }
    if (uu == 0) break;
  }
  for (int i = 1; i <= p; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
