#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
long long n, m, p, remaining = 0, nochanges = 0;
long long s[20], mx[20], ans[20], stmx[20];
long long level[N][N];
char a[N][N];
queue<pair<long long, long long> > q[20];
long long dx[4] = {0, 0, +1, -1};
long long dy[4] = {+1, -1, 0, 0};
bool check(long long x, long long y) {
  if (x < 1 || x > n || y < 1 || y > m) return 0;
  return (a[x][y] == '.');
}
void work(long long idx) {
  bool checker = 1;
  while (q[idx].size() && remaining > 0) {
    pair<long long, long long> p = q[idx].front();
    long long x = p.first;
    long long y = p.second;
    if (level[x][y] == mx[idx]) {
      nochanges += checker;
      return;
    }
    q[idx].pop();
    for (long long dir = 0; dir < 4; dir++) {
      long long nx = x + dx[dir];
      long long ny = y + dy[dir];
      if (check(nx, ny)) {
        checker = 0;
        nochanges = 0;
        ans[idx]++;
        remaining--;
        a[nx][ny] = (char)('0' + idx);
        q[idx].push({nx, ny});
        level[nx][ny] = level[x][y] + 1;
      }
    }
  }
  nochanges += checker;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> p;
  for (long long i = 1; i <= p; i++) {
    cin >> s[i];
    mx[i] = s[i];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
      remaining += (a[i][j] == '.');
      if (isdigit(a[i][j])) {
        q[a[i][j] - '0'].push({i, j});
        level[i][j] = 0;
        ans[a[i][j] - '0']++;
      }
    }
  }
  long long player = 0;
  while (remaining > 0 && nochanges < p) {
    work(player + 1);
    mx[player + 1] += s[player + 1];
    player++;
    player %= p;
  }
  for (long long i = 1; i <= p; i++) cout << ans[i] << " ";
  return 0;
}
