#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9, MN = 1010;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int vis[MN][MN];
char board[MN][MN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, p;
  cin >> n >> m >> p;
  vector<int> a(p);
  for (int i = 0; i < p; i++) cin >> a[i];
  vector<queue<tuple<int, int, int> > > q(p);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> board[i][j];
      if (board[i][j] != '.' && board[i][j] != '#') {
        int id = board[i][j] - '1';
        q[id].push(tuple<int, int, int>(i, j, a[id]));
      }
    }
  }
  vector<int> freq(p);
  int done = 0;
  while (!done) {
    done = 1;
    for (int i = 0; i < p; i++) {
      while (!q[i].empty()) {
        done = 0;
        int x, y, c;
        tie(x, y, c) = q[i].front();
        if (c == 0) break;
        q[i].pop();
        board[x][y] = i + '1';
        freq[i]++;
        for (int k = 0; k < 4; k++) {
          int nx = x + dx[k], ny = y + dy[k];
          if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
          if (board[nx][ny] == '.' && !vis[nx][ny]) {
            vis[nx][ny] = 1;
            q[i].push(tuple<int, int, int>(nx, ny, c - 1));
          }
        }
      }
      for (int j = 0; j < (int)q[i].size(); j++) {
        int x, y, c;
        tie(x, y, c) = q[i].front();
        q[i].pop();
        q[i].push(tuple<int, int, int>(x, y, a[i]));
      }
    }
  }
  for (int i = 0; i < p; i++) cout << freq[i] << " ";
  cout << '\n';
  return 0;
}
