#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
queue<pii> q[11];
char board[1005][1005];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int n, m, p, sp[11], res[11];
int main() {
  cin >> n >> m >> p;
  for (int i = 0; i < p; i++) cin >> sp[i];
  for (int i = 0; i < n; i++) {
    scanf("%s", board[i]);
    for (int j = 0; j < m; j++) {
      if (board[i][j] != '.' && board[i][j] != '#') {
        q[board[i][j] - '1'].push(make_pair(i, j));
      }
    }
  }
  while (1) {
    bool end = 1;
    for (int turn = 0; turn < p; turn++) {
      for (int ep = 0; ep < sp[turn] && !q[turn].empty(); ep++) {
        int sz = q[turn].size();
        while (sz--) {
          int x = q[turn].front().first;
          int y = q[turn].front().second;
          q[turn].pop();
          for (int i = 0; i < 4; i++) {
            int tx = x + dx[i], ty = y + dy[i];
            if (tx < 0 || ty < 0 || tx == n || ty == m) continue;
            if (board[tx][ty] == '.') {
              q[turn].push(make_pair(tx, ty));
              board[tx][ty] = board[x][y];
            }
          }
        }
      }
      if (!q[turn].empty()) end = 0;
    }
    if (end) break;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (board[i][j] != '.' && board[i][j] != '#') {
        res[board[i][j] - '1']++;
      }
    }
  for (int i = 0; i < p; i++) {
    cout << res[i] << ' ';
  }
  cout << endl;
}
