#include <bits/stdc++.h>
char board[1010][1010];
int stepb[1010][1010];
int speed[10];
int delta[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
int nextVisit[10][1010 * 1010];
int nnVisit[10][1010 * 1010];
int nextIdx[10];
int nnIdx[10];
int N, M, P;
int check(int x, int y) { return x >= 0 && y >= 0 && x < N && y < M; }
int main() {
  scanf("%d %d %d", &N, &M, &P);
  for (int i = 0; i < P; i++) scanf("%d", &speed[i]);
  for (int i = 0; i < N; i++) scanf("%s", board[i]);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cnt += (board[i][j] == '.');
      if (board[i][j] >= '1' && board[i][j] <= '9') {
        board[i][j]--;
        int p = board[i][j] - '0';
        nextVisit[p][nextIdx[p]++] = i * 1010 + j;
        stepb[i][j] = 0;
      } else
        stepb[i][j] = -1;
    }
  }
  while (cnt) {
    int prevcnt = cnt;
    for (int p = 0; p < P; p++) {
      for (int ii = 0; ii < nnIdx[p]; ii++) {
        int xy = nnVisit[p][ii];
        int i = xy / 1010;
        int j = xy % 1010;
        stepb[i][j] = 0;
        nextVisit[p][nextIdx[p]++] = i * 1010 + j;
        board[i][j] = '0' + p;
      }
      nnIdx[p] = 0;
    }
    for (int p = 0; p < P; p++) {
      int rdptr = 0;
      int wrptr = nextIdx[p];
      while (rdptr < wrptr) {
        int current = nextVisit[p][rdptr++];
        int x = current / 1010;
        int y = current % 1010;
        int step = stepb[x][y];
        if (step == speed[p]) continue;
        for (int k = 0; k < 4; k++) {
          int dx = x + delta[k][0];
          int dy = y + delta[k][1];
          if (!check(dx, dy)) continue;
          if (board[dx][dy] != '.') continue;
          cnt--;
          nnVisit[p][nnIdx[p]++] = dx * 1010 + dy;
          board[dx][dy] = 'a' + p;
          stepb[dx][dy] = step + 1;
          nextVisit[p][wrptr++] = dx * 1010 + dy;
        }
      }
    }
    for (int i = 0; i < P; i++) nextIdx[i] = 0;
    if (prevcnt == cnt) break;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (board[i][j] >= 'a') {
        board[i][j] -= 'a';
        board[i][j] += '0';
      }
    }
  }
  for (int i = 0; i < P; i++) speed[i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) speed[board[i][j] - '0']++;
  }
  for (int i = 0; i < P; i++) printf("%d ", speed[i]);
  printf("\n");
  return 0;
}
