#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
char a[1002][1002];
long long vis[1002][1002];
long long dis[1002][1002];
long long n, m, p, s[10];
queue<pair<long long, long long> > v[10];
long long ans[10];
bool valid(long long x, long long y) {
  if (x < 1 || x > n || y < 1 || y > m || a[x][y] == '#' ||
      (a[x][y] >= '1' && a[x][y] <= '9') || vis[x][y])
    return false;
  else
    return true;
}
long long bfs(long long cur) {
  long long ret = 0;
  long long loo = 0;
  queue<pair<long long, long long> > q;
  while (!v[cur].empty()) {
    loo++;
    long long x = v[cur].front().first;
    long long y = v[cur].front().second;
    v[cur].pop();
    q.push({x, y});
    vis[x][y] = 1;
    dis[x][y] = 0;
  }
  while (!q.empty()) {
    loo++;
    long long ux = q.front().first;
    long long uy = q.front().second;
    q.pop();
    bool flag = false;
    long long cnt = 0;
    for (long long k = 0; k < 4; k++) {
      long long vx = ux + dx[k];
      long long vy = uy + dy[k];
      if (valid(vx, vy) && dis[ux][uy] + 1 <= s[cur]) {
        ans[cur]++;
        vis[vx][vy] = 1;
        dis[vx][vy] = dis[ux][uy] + 1;
        a[vx][vy] = '1';
        q.push({vx, vy});
        cnt++;
        ret = 1;
      }
      if (valid(vx, vy)) flag = true;
    }
    if (flag && !cnt) v[cur].push({ux, uy});
  }
  if (loo == 0) return (long long)0;
  return ret;
}
int main() {
  scanf("%lld %lld", &n, &m);
  scanf("%lld", &p);
  for (long long i = 1; i <= p; i++) {
    scanf("%lld", &s[i]);
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      scanf(" %c", &a[i][j]);
      if (a[i][j] >= '1' && a[i][j] <= '9') {
        ans[a[i][j] - '0']++;
        v[a[i][j] - '0'].push({i, j});
      }
    }
  }
  while (true) {
    long long ret = 0;
    for (long long i = 1; i <= p; i++) {
      ret = ret | bfs(i);
    }
    if (!ret) break;
  }
  for (long long i = 1; i <= p; i++) {
    printf("%lld ", ans[i]);
  }
  printf("\n");
  return 0;
}
