#include <bits/stdc++.h>
using namespace std;
int n, m, p, v[15], G[1015][1015], sx[15], sy[15], ans[15],
    dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
string s[1015];
struct node {
  int x, y, bel;
  node() {}
  node(int a, int b, int c) {
    x = a;
    y = b;
    bel = c;
  }
};
queue<node> q[15];
bool bfs(int u) {
  while (q[u].size() > 0) {
    q[0].push(q[u].front());
    q[u].pop();
  }
  while (!q[0].empty()) {
    node cur = q[0].front();
    q[0].pop();
    for (int i = 0; i <= 3; i++) {
      int tx = cur.x + dx[i], ty = cur.y + dy[i];
      if (tx < 1 || ty < 1 || tx > n || ty > m || G[tx][ty] != 0) continue;
      G[tx][ty] = cur.bel;
      q[u].push(node(tx, ty, cur.bel));
    }
  }
  return q[u].size() > 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> v[i], v[i] = min(v[i], 1000);
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j - 1] == '.')
        G[i][j] = 0;
      else if (s[i][j - 1] == '#')
        G[i][j] = -1;
      else {
        G[i][j] = s[i][j - 1] - '0';
        sx[G[i][j]] = i;
        sy[G[i][j]] = j;
        q[G[i][j]].push(node(i, j, G[i][j]));
      }
    }
  }
  while (1) {
    bool flag = 0;
    for (int i = 1; i <= p; i++) {
      for (int j = 1; j <= v[i]; j++) {
        if (bfs(i) != 0)
          flag = 1;
        else
          break;
      }
    }
    if (!flag) break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (G[i][j] > 0) {
        ans[G[i][j]]++;
      }
    }
  }
  for (int i = 1; i <= p; i++) cout << ans[i] << ' ';
  return 0;
}
