#include <bits/stdc++.h>
using namespace std;
void bye() { exit(0); }
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
bool in(int x, int y, int n, int m) {
  return (x >= 0 && y >= 0 && x < n && y < m);
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int t, pro = 1, temp, k, n, m, i, j, l, r, mid, x, y, z, rem, ind,
                   ans = 0, mx = LONG_LONG_MIN, mn = LONG_LONG_MAX, cnt = 0,
                   curr = 0, prev, sum = 0, flag = 0, i1 = -1, i2 = -1;
  cin >> n >> m >> k;
  long long int a[k + 1], rg[k + 1];
  for (i = 1; i <= k; i++) {
    rg[i] = 0;
    cin >> a[i];
    a[i] = min(a[i], n * m);
  }
  string s[n];
  vector<pair<int, int>> adj[k + 1];
  for (i = 0; i <= n - 1; i++) {
    cin >> s[i];
    for (j = 0; j <= m - 1; j++) {
      if (s[i][j] != '.' && s[i][j] != '#') {
        adj[s[i][j] - '0'].push_back({i, j});
      }
    }
  }
  bool okay = true;
  while (okay) {
    okay = false;
    for (i = 1; i <= k; i++) {
      vector<pair<int, int>> prs;
      queue<pair<pair<int, int>, int>> mq;
      for (auto it : adj[i]) {
        mq.push({it, a[i]});
      }
      while (!mq.empty()) {
        auto it = mq.front();
        mq.pop();
        x = it.first.first;
        y = it.first.second;
        z = it.second;
        for (j = 0; j <= 3; j++) {
          if (in(x + dx[j], y + dy[j], n, m) &&
              s[x + dx[j]][y + dy[j]] == '.') {
            s[x + dx[j]][y + dy[j]] = i + '0';
            prs.push_back({x + dx[j], y + dy[j]});
            okay = true;
            if (z > 1) {
              mq.push({{x + dx[j], y + dy[j]}, z - 1});
            }
          }
        }
      }
      adj[i] = prs;
    }
  }
  for (i = 0; i <= n - 1; i++) {
    for (j = 0; j <= m - 1; j++) {
      if (s[i][j] != '.' && s[i][j] != '#') {
        rg[s[i][j] - '0']++;
      }
    }
  }
  for (i = 1; i <= k; i++) {
    cout << rg[i] << ' ';
  }
  return 0;
}
