#include <bits/stdc++.h>
int tsts;
using namespace std;
const int N = 1e3 + 7;
int mp[N][N];
int s[10];
int n, m, pcount;
char tmp;
queue<pair<int, int>> pqueue[10];
int cnt[10];
int di[] = {-1, 0, 0, 1};
int dj[] = {0, -1, 1, 0};
int main() {
  scanf("%d%d%d", &n, &m, &pcount);
  for (int i = 0; i < pcount; i++) {
    scanf("%d", s + i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &tmp);
      if (tmp == '#')
        mp[i][j] = -1;
      else if (tmp == '.')
        mp[i][j] = 0;
      else {
        int pp = tmp - '0';
        mp[i][j] = pp;
        pqueue[pp - 1].emplace(i, j);
        cnt[pp - 1]++;
      }
    }
  }
  while (true) {
    bool change = 0;
    for (int p = 0; p < pcount; ++p) {
      int lvl = 0;
      while (!pqueue[p].empty()) {
        int sz = pqueue[p].size();
        while (sz--) {
          for (int k = 0; k < 4; k++) {
            int ni = pqueue[p].front().first + di[k];
            int nj = pqueue[p].front().second + dj[k];
            if (ni < 0 || nj < 0 || ni >= n || nj >= m) continue;
            if (mp[ni][nj] == 0) {
              mp[ni][nj] = p + 1;
              pqueue[p].emplace(ni, nj);
              cnt[p]++;
              change = 1;
            }
          }
          pqueue[p].pop();
        }
        if (++lvl == s[p]) break;
      }
    }
    if (!change) break;
  }
  for (int i = 0; i < pcount; ++i) {
    printf("%d ", cnt[i]);
  }
}
