#include <bits/stdc++.h>
using namespace std;
long long n, m, p;
int s[10];
string a[1001];
int occ = 0;
bool vis[1001][1001] = {false};
queue<pair<pair<int, int>, int> > q[10];
int ans[10] = {0};
bool func(int curr) {
  if (q[curr].empty()) return false;
  int tot = s[curr];
  int prev = (q[curr].front()).second;
  int x[] = {-1, 0, 1, 0};
  int y[] = {0, 1, 0, -1};
  while (!q[curr].empty()) {
    pair<pair<int, int>, int> t = q[curr].front();
    if (t.second - prev == s[curr]) break;
    int i = t.first.first, j = t.first.second;
    q[curr].pop();
    for (int k = 0; k < 4; k++) {
      int new_i = i + y[k], new_j = j + x[k];
      if (new_i <= 0 or new_i > n) continue;
      if (new_j <= 0 or new_j > m) continue;
      if (vis[new_i][new_j]) continue;
      if (a[new_i][new_j] == '#') continue;
      vis[new_i][new_j] = true;
      occ++;
      q[curr].push(make_pair(make_pair(new_i, new_j), t.second + 1));
      ans[curr]++;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = '#' + a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '#') {
        occ++;
        continue;
      }
      if (a[i][j] == '.') continue;
      vis[i][j] = true;
      int dig = a[i][j] - '0';
      q[dig].push(make_pair(make_pair(i, j), 0));
      ans[dig]++;
      occ++;
    }
  }
  while (occ < n * m) {
    bool canMove = false;
    for (int i = 1; i <= p; i++) {
      bool temp = func(i);
      canMove = canMove || temp;
    }
    if (canMove == false) break;
  }
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  return 0;
}
