#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 5;
int n, m, p;
int s[10];
char g[MAXN][MAXN];
queue<pair<int, int> > nxt[10];
vector<pair<int, int> > temp;
int ans[10];
int d[MAXN][MAXN];
int dr[4] = {0, 0, 1, -1};
int dc[4] = {1, -1, 0, 0};
bool valid(int r, int c) { return 0 <= r && r < n && 0 <= c && c < m; }
void bfs() {
  memset(d, -1, sizeof(d));
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c = g[i][j];
      if (c != '.') {
        d[i][j] = 0;
        if (isdigit(c)) {
          nxt[c - '1'].push({i, j});
          ans[c - '1']++;
        }
      }
    }
  bool f = 1;
  while (f) {
    for (int k = 0; k < p; k++) {
      temp.clear();
      while (!nxt[k].empty()) {
        pair<int, int> pp = nxt[k].front();
        nxt[k].pop();
        int cr = pp.first;
        int cc = pp.second;
        for (int i = 0; i < 4; i++) {
          int r = cr + dr[i];
          int c = cc + dc[i];
          if (valid(r, c) && d[r][c] == -1) {
            ans[k]++;
            if (d[cr][cc] + 1 == s[k]) {
              d[r][c] = 0;
              temp.push_back({r, c});
              continue;
            }
            d[r][c] = d[cr][cc] + 1;
            nxt[k].push({r, c});
          }
        }
      }
      for (pair<int, int> pp : temp) nxt[k].push(pp);
    }
    f = 0;
    for (int i = 0; i < p; i++) f |= !nxt[i].empty();
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 0; i < p; i++) scanf("%d", &s[i]);
  for (int i = 0; i < n; i++) scanf("%s", g[i]);
  bfs();
  for (int i = 0; i < p; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
