#include <bits/stdc++.h>
using namespace std;
struct node {
  int x;
  int y;
  int step;
  node() {}
  node(int _x, int _y, int _step) {
    x = _x;
    y = _y;
    step = _step;
  }
};
int s[15];
queue<node> q[15][2];
char mp[1005][1005];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int ans[15];
int main() {
  int n, m, p, nowq, tx, ty;
  node now;
  bool f;
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; i++) scanf("%d", &s[i]);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  nowq = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mp[i][j] >= '0' && mp[i][j] <= '9')
        q[mp[i][j] - '0'][nowq].push(node(i, j, 0));
  f = true;
  while (f) {
    f = false;
    for (int i = 1; i <= p; i++) {
      while (!q[i][nowq].empty()) {
        now = q[i][nowq].front();
        q[i][nowq].pop();
        if (now.step == s[i]) continue;
        for (int j = 0; j < 4; j++) {
          tx = now.x + dx[j];
          ty = now.y + dy[j];
          if (tx >= 0 && tx < n && ty >= 0 && ty < m && mp[tx][ty] == '.') {
            mp[tx][ty] = '0' + i;
            q[i][nowq].push(node(tx, ty, now.step + 1));
            q[i][nowq ^ 1].push(node(tx, ty, 0));
            f = true;
          }
        }
      }
    }
    nowq ^= 1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mp[i][j] >= '0' && mp[i][j] <= '9') ans[mp[i][j] - '0']++;
  for (int i = 1; i <= p; i++)
    if (i != p)
      printf("%d ", ans[i]);
    else
      printf("%d\n", ans[i]);
  return 0;
}
