#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int n, m, k;
bool ch(int x, int y) { return (x < n && x >= 0 && y < m && y >= 0); }
int32_t main() {
  cin >> n >> m >> k;
  vector<queue<pair<int, int>>> q(k), qq;
  vector<vector<vector<int>>> d(k, vector<vector<int>>(n, vector<int>(m, 1e9)));
  vector<int> s(k);
  for (int i = 0; i < k; i++) cin >> s[i];
  vector<vector<char>> a(n, vector<char>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] != '.' && a[i][j] != '#') {
        q[a[i][j] - '1'].push({i, j});
      }
    }
  qq = q;
  for (int i = 0; i < k; i++) {
    while (!q[i].empty()) {
      int x = q[i].front().first, y = q[i].front().second;
      if (d[i][x][y] == 1e9) d[i][x][y] = 0;
      q[i].pop();
      for (int j = 0; j < 4; j++) {
        if (ch(x + dx[j], y + dy[j]) && a[x + dx[j]][y + dy[j]] == '.' &&
            d[i][x + dx[j]][y + dy[j]] == 1e9) {
          d[i][x + dx[j]][y + dy[j]] = d[i][x][y] + 1;
          q[i].push({x + dx[j], y + dy[j]});
        }
      }
    }
  }
  q = qq;
  int kek = 0;
  vector<int> ans(k);
  while (1) {
    bool fl = 0;
    for (int i = 0; i < k; i++) {
      while (1) {
        if (q[i].empty() ||
            (d[i][q[i].front().first][q[i].front().second]) / s[i] != kek) {
          break;
        }
        int x = q[i].front().first, y = q[i].front().second;
        if (a[q[i].front().first][q[i].front().second] == char(i + '1')) {
          for (int j = 0; j < 4; j++)
            if (ch(x + dx[j], y + dy[j]) && a[x + dx[j]][y + dy[j]] == '.') {
              q[i].push({x + dx[j], y + dy[j]});
              a[x + dx[j]][y + dy[j]] = char(i + '1');
            }
          ans[i]++;
        }
        fl = 1;
        q[i].pop();
      }
    }
    if (!fl) break;
    kek++;
  }
  for (auto i : ans) cout << i << " ";
  return 0;
}
