#include <bits/stdc++.h>
using namespace std;
char S[1008];
int n, m, p, cnt;
int a[1008][1008], ans[10], flag[10];
long long s[10], maxn[10];
int x[4] = {0, 0, 1, -1}, y[4] = {1, -1, 0, 0};
struct node {
  int x, y, d;
};
queue<node> q[10];
void bfs(int turn) {
  node t, nxt;
  flag[turn] = 0;
  while (!q[turn].empty()) {
    t = q[turn].front();
    if ((long long)t.d == maxn[turn]) return;
    q[turn].pop();
    for (int i = 0; i < 4; i++) {
      nxt = t;
      nxt.x += x[i];
      nxt.y += y[i];
      nxt.d++;
      if (nxt.x < 1 || nxt.x > n || nxt.y < 1 || nxt.y > m ||
          a[nxt.x][nxt.y] != 0)
        continue;
      a[nxt.x][nxt.y] = turn;
      ans[turn]++;
      cnt++;
      flag[turn] = 1;
      q[turn].push(nxt);
    }
  }
}
int main() {
  node t;
  scanf("%d%d%d", &n, &m, &p);
  int sum = n * m, turn = 1;
  for (int i = 1; i <= p; i++) {
    flag[i] = 1;
    scanf("%I64d", &s[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%s", S);
    for (int j = 1; j <= m; j++) {
      if (S[j - 1] == '#')
        a[i][j] = -1, ++cnt;
      else if (S[j - 1] == '.')
        a[i][j] = 0;
      else {
        ++cnt;
        a[i][j] = S[j - 1] - '0';
        t.x = i;
        t.y = j, t.d = 0;
        q[a[i][j]].push(t);
        ans[a[i][j]]++;
      }
    }
  }
  int ok = 0;
  while (ok < p) {
    if (flag[turn]) {
      maxn[turn] += s[turn];
      bfs(turn);
      if (flag[turn] == 0) ok++;
    }
    turn = (turn + 1) % p;
    if (turn == 0) turn = p;
  }
  for (int i = 1; i <= p; i++) printf("%d%c", ans[i], i == p ? '\n' : ' ');
  return 0;
}
