#include <bits/stdc++.h>
using namespace std;
const long long int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
const long long int MOD = 1e9 + 7;
long long int n, m, p;
long long int v[10];
char mat[1010][1010];
long long int d[1010][1010][10];
long long int vis[1010][1010];
long long int dx[4] = {1, -1, 0, 0};
long long int dy[4] = {0, 0, 1, -1};
queue<pair<pair<int, int>, int>> q[10];
bool is(long long int i, long long int j) {
  if (i >= n || i < 0 || j >= m | j < 0) return false;
  if (mat[i][j] == '#') return false;
  if (mat[i][j] == '.') return true;
  return false;
}
bool dist(long long int s, long long int ct) {
  bool ok = false;
  if (ct == 1) {
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        if (mat[i][j] == '0' + s) {
          q[s].push(make_pair(make_pair(i, j), 0));
        }
      }
    }
  }
  while (!q[s].empty()) {
    ok = true;
    pair<pair<int, int>, int> aux = q[s].front();
    if (v[s] * ct < aux.second) break;
    q[s].pop();
    long long int x = aux.first.first;
    long long int y = aux.first.second;
    long long int dd = aux.second;
    if (vis[x][y] == 1) continue;
    vis[x][y] = 1;
    mat[x][y] = '0' + s;
    d[x][y][s] = dd;
    for (long long int i = 0; i < 4; i++) {
      if (is(x + dx[i], y + dy[i])) {
        if (vis[x + dx[i]][y + dy[i]] == 0) {
          q[s].push(make_pair(make_pair(x + dx[i], y + dy[i]), dd + 1));
        }
      }
    }
  }
  return ok;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> p;
  for (long long int i = 1; i <= p; i++) cin >> v[i];
  string s;
  getline(cin, s);
  for (long long int i = 0; i < n; i++) {
    getline(cin, s);
    for (long long int j = 0; j < m; j++) {
      mat[i][j] = s[j];
    }
  }
  memset(d, INF, sizeof(d));
  for (long long int ct = 1; ct <= m * n; ct++) {
    bool aux = false;
    for (long long int i = 1; i <= p; i++) {
      aux = aux | dist(i, ct);
    }
    if (aux == false) break;
  }
  long long int ans[10];
  memset(ans, 0, sizeof(ans));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      for (long long int k = 1; k <= p; k++) {
        if (mat[i][j] == '0' + k) ans[k]++;
      }
    }
  }
  for (long long int i = 1; i <= p; i++) cout << ans[i] << ' ';
  cout << endl;
}
