#include <bits/stdc++.h>
using namespace std;
string mat[1000];
int n, m, p, s[10], dist[10][1000][1000], cont[10];
queue<pair<int, int> > Q[10];
int mi[] = {0, 1, 0, -1}, mj[] = {1, 0, -1, 0};
void BFS(int np) {
  queue<pair<int, int> > lQ;
  while (Q[np].size()) {
    pair<int, int> cord = Q[np].front();
    int i = cord.first, j = cord.second;
    if (mat[i][j] != '.') {
      if (mat[i][j] == '0' + np) {
        if (dist[np][i][j] == s[np]) dist[np][i][j] = 0;
      } else {
        Q[np].pop();
        continue;
      }
    }
    if (mat[i][j] == '.') mat[i][j] = '0' + np, cont[np]++;
    if (dist[np][i][j] == s[np]) {
      Q[np].pop();
      lQ.push({i, j});
      continue;
    }
    for (int k = 0; k < 4; k++) {
      int y = i + mi[k], x = j + mj[k];
      if (y >= 0 && y < n && x >= 0 && x < m && mat[y][x] == '.' &&
          dist[np][y][x] > dist[np][i][j] + 1)
        Q[np].push({i + mi[k], j + mj[k]}), dist[np][y][x] = dist[np][i][j] + 1;
    }
    Q[np].pop();
  }
  Q[np] = lQ;
}
int main() {
  cin >> n >> m >> p;
  memset(dist, 1, sizeof(dist));
  for (int i = 1; i <= p; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
    for (int j = 0; j < m; j++) {
      if (mat[i][j] != '.' && mat[i][j] != '#') {
        int l = mat[i][j] - '0';
        Q[l].push({i, j});
        dist[l][i][j] = 0;
        cont[l]++;
      }
    }
  }
  bool mov = true;
  while (mov) {
    mov = false;
    for (int i = 1; i <= p; i++)
      if (Q[i].size()) mov = true, BFS(i);
  }
  for (int i = 1; i <= p; i++) cout << cont[i] << " ";
}
