#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
vector<queue<pair<long long int, long long int>>> v(20);
vector<long long int> ans(1005);
long long int n, m, p, s[1005], d[1005][1005], lvl = 1, dx[4] = {0, 0, 1, -1},
                                               dy[4] = {1, -1, 0, 0};
bool ok(long long int a, long long int b) {
  return (a > 0 && a <= n && b > 0 && b <= m);
}
void solve() {
  cin >> n >> m >> p;
  for (long long int i = 1; i < p + 1; i++) cin >> s[i];
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < m + 1; j++) {
      char c;
      cin >> c;
      a[i][j] = c;
      if (c != '#' && c != '.') v[c - '0'].push({i, j});
    }
  }
  bool f = 1;
  while (f) {
    f = 0;
    for (long long int i = 1; i < p + 1; i++) {
      while (!v[i].empty()) {
        f = 1;
        pair<long long int, long long int> t = v[i].front();
        if (d[t.first][t.second] >= lvl * s[i]) break;
        v[i].pop();
        long long int x = t.first, y = t.second;
        for (long long int j = 0; j < 4; j++) {
          long long int nx = x + dx[j], ny = y + dy[j];
          if (ok(nx, ny) && a[nx][ny] == '.') {
            a[nx][ny] = (char)(i + '0');
            d[nx][ny] = d[x][y] + 1;
            v[i].push({nx, ny});
          }
        }
      }
    }
    lvl++;
  }
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < m + 1; j++) {
      if (a[i][j] <= '9' && a[i][j] > '0') ans[a[i][j] - '0']++;
    }
  }
  for (long long int i = 1; i < p + 1; i++) cout << ans[i] << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  while (T--) solve();
  return 0;
}
