#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
const int mod = (int)1e9 + 7;
int ans[maxn];
int n, m, k, l, t, r, T;
int a[maxn];
int uvw;
int mp[1005][1005];
int dis[1005][1005];
int p;
int s[maxn];
string tmp;
int dx[] = {0, 0, 1, -1}, dy[] = {-1, 1, 0, 0};
struct st {
  int x, y;
};
queue<st> node[20];
int flag[maxn];
int is(int x) {
  if (x >= '0' && x <= '9') return 1;
  return 0;
}
int bfs(int x) {
  int ery = 0;
  queue<st> q;
  while (!q.empty()) q.pop();
  while (!node[x].empty()) {
    st tmp = node[x].front();
    dis[tmp.x][tmp.y] = 0;
    q.push(tmp);
    node[x].pop();
  }
  while (!q.empty()) {
    st now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nowx = now.x + dx[i], nowy = now.y + dy[i];
      if (nowx < 1 || nowx > n || nowy < 1 || nowy > m || mp[nowx][nowy] != 0)
        continue;
      mp[nowx][nowy] = x;
      uvw++;
      ery++;
      st temp;
      temp.x = nowx;
      temp.y = nowy;
      if (dis[now.x][now.y] == s[x] - 1) {
        node[x].push(temp);
      } else {
        dis[nowx][nowy] = dis[now.x][now.y] + 1;
        q.push(temp);
      }
    }
  }
  return ery;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) flag[i] = 1;
  for (int i = 1; i <= p; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    cin >> tmp;
    for (int j = 1; j <= m; j++)
      if (tmp[j - 1] == '.')
        mp[i][j] = 0;
      else if (tmp[j - 1] == '#')
        mp[i][j] = -1, uvw++;
      else if (is(tmp[j - 1])) {
        mp[i][j] = tmp[j - 1] - '0';
        st nop;
        nop.x = i;
        nop.y = j;
        node[mp[i][j]].push(nop);
        uvw++;
      }
  }
  int play = -1;
  int u = 0;
  while (1) {
    play++;
    play %= p;
    if (bfs(play + 1) == 0 && flag[play + 1] == 1) u++, flag[play + 1] = 0;
    if (uvw >= n * m || u == p) break;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (mp[i][j] >= 1) ans[mp[i][j]]++;
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  return 0;
}
