#include <bits/stdc++.h>
using namespace std;
struct player {
  long long int x, y, num;
  player(long long int xp, long long int yp, long long int nump) {
    x = xp, y = yp, num = nump;
  }
};
const long long int M = 17;
const long long int N = 1007;
long long int second[M], ans[M];
long long int vis[N][N];
queue<player> q[17];
long long int dx[] = {1, 0, -1, 0};
long long int dy[] = {0, 1, 0, -1};
bool isok(long long int x, long long int y, long long int n, long long int m) {
  if (vis[x][y]) return false;
  if (x < 1 || x > n || y < 1 || y > m) return false;
  return true;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, push, i, j, u, v;
  char x;
  cin >> n >> m >> push;
  for (i = 1; i <= push; i++) cin >> second[i];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> x;
      if (x != '.') vis[i][j] = 1;
      if (x == '#' || x == '.') continue;
      long long int num = (long long int)x - '0';
      player np(i, j, 0);
      q[num].push(np);
      ans[num]++;
    }
  long long int cnum = 1;
  while (true) {
    bool verif = 0;
    for (i = 1; i <= push; i++) {
      while (!q[i].empty() && q[i].front().num < cnum * second[i]) {
        player tp = q[i].front();
        q[i].pop();
        for (j = 0; j < 4; j++) {
          player np(tp.x + dx[j], tp.y + dy[j], 1 + tp.num);
          if (isok(np.x, np.y, n, m)) {
            ans[i]++;
            q[i].push(np);
            vis[np.x][np.y] = 1;
            verif = 1;
          }
        }
      }
    }
    if (!verif) break;
    cnum++;
  }
  for (i = 1; i <= push; i++) cout << ans[i] << " ";
  cout << '\n';
  return 0;
}
