#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const int maxn = 1e3 + 5;
int n, m, p, mp[maxn][maxn], sp[15];
struct node {
  int x;
  int y;
  node() {}
  node(int xx, int yy) { x = xx, y = yy; }
};
queue<node> q[15];
int allnum = 0;
int ans[15];
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
void pbfs(int np) {
  int prenum = allnum;
  for (int i = 1; i <= sp[np]; ++i) {
    int msize = q[np].size();
    prenum = allnum;
    while (msize) {
      msize--;
      node nt = q[np].front();
      q[np].pop();
      int nx = nt.x, ny = nt.y;
      for (int i = 0; i < 4; ++i) {
        int tx = nx + dx[i], ty = ny + dy[i];
        if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && mp[tx][ty] == 0) {
          allnum++;
          mp[tx][ty] = np;
          q[np].push(node(tx, ty));
          ans[np]++;
        }
      }
    }
    if (prenum == allnum) break;
  }
}
void bfs() {
  if (allnum == n * m) return;
  int prenum = allnum;
  for (int i = 1; i <= p; ++i) {
    if (ans[i]) pbfs(i);
  }
  if (allnum == prenum) return;
  bfs();
}
int main() {
  std::ios::sync_with_stdio(0);
  cin >> n >> m >> p;
  int ms = max(n, m);
  for (int i = 1; i <= p; ++i) {
    cin >> sp[i];
    sp[i] = min(sp[i], ms);
  }
  char tp;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> tp;
      if (tp == '.') {
        mp[i][j] = 0;
        continue;
      }
      if (tp == '#') {
        mp[i][j] = -1;
        allnum++;
        continue;
      }
      int t = tp - '0';
      mp[i][j] = t;
      q[t].push(node(i, j));
      allnum++;
      ans[t]++;
    }
  }
  bfs();
  for (int i = 1; i <= p; ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
