#include <bits/stdc++.h>
using namespace std;
struct lol {
  int first, second, s;
};
char a[1005][1005];
int b[15];
queue<lol> Q;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int smx, idx;
vector<pair<int, int> > V[15];
int n, m, p;
int rs[15];
bool OK(int i, int j) { return (i >= 1 && j >= 1 && j <= m && i <= n); }
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= p; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] >= '0' && a[i][j] <= '9') {
        V[a[i][j] - '0'].push_back({i, j});
        rs[a[i][j] - '0']++;
      }
    }
  }
  bool v = 1;
  while (v) {
    v = 0;
    for (int i = 1; i <= p; ++i) {
      idx = i;
      for (auto it : V[i]) Q.push({it.first, it.second, 0});
      V[i].clear();
      while (Q.size()) {
        int i1 = Q.front().first;
        int j1 = Q.front().second;
        int s = Q.front().s;
        Q.pop();
        if (s == b[i]) {
          for (int d = 0; d < 4; ++d) {
            int i2 = i1 + dx[d];
            int j2 = j1 + dy[d];
            if (OK(i2, j2) && a[i2][j2] == '.') {
              V[i].push_back({i1, j1});
              break;
            }
          }
          continue;
        }
        for (int d = 0; d < 4; ++d) {
          int i2 = i1 + dx[d];
          int j2 = j1 + dy[d];
          if (OK(i2, j2) && a[i2][j2] == '.') {
            a[i2][j2] = i - 0 + '0';
            rs[i]++;
            Q.push({i2, j2, s + 1});
            v = 1;
          }
        }
      }
    }
  }
  for (int i = 1; i <= p; ++i) cout << rs[i] << " ";
  return 0;
}
