#include <bits/stdc++.h>
using namespace std;
int n, m, p, s[1010], ans[1010];
int g[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
char mp[1010][1010];
struct node {
  int x, y;
  int t;
} temp;
queue<node> que[10];
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &mp[i][j]);
      if (mp[i][j] >= '1' && mp[i][j] <= '9') {
        que[mp[i][j] - '0'].push((node){i, j, 0});
        ans[mp[i][j] - '0']++;
      }
    }
  }
  while (1) {
    bool check = true;
    for (int i = 1; i <= p; i++)
      if (!que[i].empty()) check = false;
    if (check) break;
    for (int i = 1; i <= p; i++) {
      if (!que[i].empty()) {
        int t = s[i];
        while (t--) {
          if (que[i].empty()) break;
          int col = que[i].front().t;
          while (!que[i].empty()) {
            temp = que[i].front();
            if (temp.t != col) break;
            que[i].pop();
            for (int j = 0; j < 4; j++) {
              int tx = temp.x + g[j][0], ty = temp.y + g[j][1];
              if (mp[tx][ty] == '.') {
                mp[tx][ty] = i + '0';
                ans[i]++;
                que[i].push((node){tx, ty, col + 1});
              }
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= p; i++) printf("%d ", ans[i]);
  return 0;
}
