#include <bits/stdc++.h>
using namespace std;
const long long modn = 1000000007;
const int INF = 0x3f3f3f3f;
int n, m, p;
int s[10];
char str[1010][1010];
int ans[10];
int now[10];
struct pii {
  int x, y;
  int dist;
};
queue<pii> q[10];
const int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void init() {
  cin >> n >> m >> p;
  for (int i = 0; i < p; i++) scanf("%d", &s[i]);
  for (int i = 0; i < n; i++) {
    scanf("%s", str[i]);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (str[i][j] >= '1' && str[i][j] <= '9') {
        ans[str[i][j] - '1']++;
        for (int k = 0; k < 4; k++) {
          int xx = i + dir[k][0];
          int yy = j + dir[k][1];
          if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
          if (str[xx][yy] == '.') q[str[i][j] - '1'].push(pii{xx, yy, 1});
        }
      }
    }
}
int solve(int i) {
  int t = 0;
  while (!q[i].empty()) {
    pii pt = q[i].front();
    if (str[pt.x][pt.y] != '.') {
      q[i].pop();
      continue;
    }
    if (pt.dist > now[i] + s[i]) {
      break;
    }
    str[pt.x][pt.y] = i + '1';
    t++;
    ans[i]++;
    for (int k = 0; k < 4; k++) {
      int xx = pt.x + dir[k][0];
      int yy = pt.y + dir[k][1];
      if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
      if (str[xx][yy] == '.') q[i].push(pii{xx, yy, pt.dist + 1});
    }
  }
  now[i] += s[i];
  return t;
}
int main() {
  init();
  while (1) {
    int t = 0;
    for (int i = 0; i < p; i++) {
      t += solve(i);
    }
    if (t == 0) break;
  }
  for (int i = 0; i < p; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  return 0;
}
