#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n, m, p, s[10], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, tot[10];
char a[1001][1001];
queue<pair<int, int> > q[10];
bool check() {
  for (int i = 1; i <= p; i++) {
    if (!q[i].empty()) {
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (register int i = 1; i <= p; i++) {
    scanf("%d", &s[i]);
    if (s[i] > n * m) {
      s[i] = n * m;
    }
  }
  getchar();
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= m; j++) {
      scanf("%c", &a[i][j]);
      if (isdigit(a[i][j])) {
        q[a[i][j] - '0'].push(make_pair(i, j));
      }
    }
    getchar();
  }
  while (check()) {
    for (register int i = 1; i <= p; i++) {
      if (q[i].empty()) {
        continue;
      }
      for (int j = 1; j <= s[i]; j++) {
        if (q[i].empty()) {
          break;
        }
        int tmp = 0, sz = q[i].size();
        while (tmp < sz && !q[i].empty()) {
          pair<int, int> temp = q[i].front();
          q[i].pop();
          tmp++;
          int x = temp.first, y = temp.second;
          for (register int k = 0; k < 4; k++) {
            int tx = x + dx[k], ty = y + dy[k];
            if (tx < 1 || tx > n || ty < 1 || ty > m || a[tx][ty] != '.') {
              continue;
            }
            a[tx][ty] = i + '0';
            q[i].push(make_pair(tx, ty));
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (isdigit(a[i][j])) tot[a[i][j] - '0']++;
    }
  }
  for (register int i = 1; i <= p; i++) {
    printf("%d ", tot[i]);
  }
  return 0;
}
