#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int T[1000][1000];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int n, m, p;
int tot[9];
struct field {
  int y, x, p, d;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> p;
  int S[p];
  for (int i = 0; i < p; ++i) {
    cin >> S[i];
    tot[i] = 0;
  }
  string s;
  vector<pair<int, int> > P[9];
  for (int i = 0; i < n; ++i) {
    cin >> s;
    for (int j = 0; j < m; ++j) {
      T[i][j] = (s[j] == '.' ? -1 : s[j] - 49);
      if (T[i][j] > -1) {
        tot[T[i][j]]++;
        P[T[i][j]].push_back({i, j});
      }
    }
  }
  queue<field> Q;
  for (int i = 0; i < p; ++i) {
    for (auto& x : P[i]) {
      Q.push({x.first, x.second, i, 0});
    }
  }
  while (!Q.empty()) {
    queue<field> cb;
    int pid = Q.front().p;
    while (!Q.empty() && Q.front().p == pid) {
      cb.push(Q.front());
      Q.pop();
    }
    while (!cb.empty()) {
      field x = cb.front();
      cb.pop();
      if (x.d == S[pid]) continue;
      for (int i = 0; i < 4; ++i) {
        int nx = x.x + dx[i];
        int ny = x.y + dy[i];
        if (nx >= 0 && nx < m && ny >= 0 && ny < n && T[ny][nx] == -1) {
          T[ny][nx] = pid;
          tot[pid]++;
          Q.push({ny, nx, pid, 0});
          cb.push({ny, nx, pid, x.d + 1});
        }
      }
    }
  }
  for (int i = 0; i < p; ++i) cout << tot[i] << " ";
  cout << (char)10;
}
