#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int mod = (1e9) + 7;
const double eps = 1e-10;
const int siz = 2e5 + 5, siz2 = 256, lg = 21, block = 317, block2 = 1000,
          extrm[2] = {INT_MIN, INT_MAX};
int n, m, p, sp[10];
struct el {
  int x, y, c;
  ;
};
queue<el> q[10];
int board[1005][1005], ver[1005][1005];
pair<int, int> d[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int ans[10];
bool valid(int v, int lim) { return v >= 0 && v < lim; }
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; i++) {
    scanf("%d", &sp[i]);
  }
  char tmp;
  scanf("%c", &tmp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &board[i][j]);
      if (board[i][j] >= '1' && board[i][j] <= '9') {
        q[board[i][j] - '0'].push({i, j, 0});
      }
    }
    char tmp;
    scanf("%c", &tmp);
  }
  for (int i = 1;; i++) {
    bool moved = false;
    for (int j = 1; j <= p; j++) {
      while (!q[j].empty()) {
        el e = q[j].front();
        int xv = e.x, yv = e.y, val = e.c;
        if (ver[xv][yv] != i) {
          val = 0;
        }
        if (val == sp[j]) {
          break;
        }
        q[j].pop();
        for (int ii = 0; ii < 4; ii++) {
          int nx = xv + d[ii].first, ny = yv + d[ii].second;
          if (valid(nx, n) && valid(ny, m) && board[nx][ny] == '.') {
            moved = true;
            ver[nx][ny] = i;
            q[j].push({nx, ny, val + 1});
            board[nx][ny] = j + '0';
          }
        }
      }
    }
    if (!moved) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (board[i][j] >= '1' && board[i][j] <= '9') {
        ans[board[i][j] - '0']++;
      }
    }
  }
  for (int i = 1; i <= p; i++) {
    printf("%d%s", ans[i], (i < p ? " " : "\n"));
  }
  return 0;
}
