#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int s[15];
char c[1005][1005];
int a[1005][1005];
int vis[1005][1005];
int cnt[15];
const int dir[2][4] = {{0, 0, 1, -1}, {1, -1, 0, 0}};
struct point {
  int x, y, t;
};
vector<point> v[1005];
queue<point> q[1005];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
int bfs(int x) {
  int cnt = 0;
  for (int i = 0; i < v[x].size(); i++)
    q[x].push(point{v[x][i].x, v[x][i].y, 0});
  v[x].clear();
  while (!q[x].empty()) {
    point u = q[x].front();
    q[x].pop();
    if (u.t == s[x]) {
      v[x].push_back(u);
      continue;
    }
    for (int i = 0; i < 4; i++) {
      int dx = u.x + dir[0][i], dy = u.y + dir[1][i];
      if (dx >= 1 && dx <= n && dy >= 1 && dy <= m && a[dx][dy] != -1 &&
          !vis[dx][dy] && u.t + 1 <= s[x]) {
        cnt++;
        q[x].push(point{dx, dy, u.t + 1});
        vis[dx][dy] = x;
      }
    }
  }
  if (cnt >= 1)
    return 1;
  else
    return 0;
}
int main() {
  n = read(), m = read(), p = read();
  for (int i = 1; i <= p; i++) s[i] = read();
  for (int i = 1; i <= n; i++) scanf("%s", (c[i] + 1));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '#')
        a[i][j] = -1;
      else if (c[i][j] >= '1' && c[i][j] <= '9')
        vis[i][j] = c[i][j] - '0', v[vis[i][j]].push_back(point{i, j, 0});
    }
  while (1) {
    int sum = 0;
    for (int i = 1; i <= p; i++) sum += bfs(i);
    if (sum == 0) break;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cnt[vis[i][j]]++;
  for (int i = 1; i <= p; i++) cout << cnt[i] << ' ';
  cout << endl;
  return 0;
}
