#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1010;
struct node {
  int x, y, step;
  node(int a = 0, int b = 0, int c = 0) : x(a), y(b), step(c) {}
};
int m, n, p;
int dir[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
queue<node> q, q1[10];
char mp[N][N];
int vis[N][N], ans[N], speed[N];
bool check(int x, int y) {
  if (x > 0 && x <= n && y > 0 && y <= m && !vis[x][y]) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> speed[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mp[i][j];
      if (mp[i][j] != '.') {
        vis[i][j] = 1;
        if (mp[i][j] > '0' && mp[i][j] <= '9') {
          q1[mp[i][j] - '0'].push(node(i, j, speed[mp[i][j] - '0']));
          ans[mp[i][j] - '0']++;
        }
      }
    }
  }
  while (true) {
    int flag = 0;
    for (int i = 1; i <= p; i++) {
      while (q1[i].size()) {
        flag = 1;
        q.push(q1[i].front());
        q1[i].pop();
      }
      while (q.size()) {
        node now = q.front();
        q.pop();
        if (now.step == 0) {
          q1[i].push(node(now.x, now.y, speed[i]));
          continue;
        }
        for (int j = 0; j < 4; j++) {
          int dx = now.x + dir[j][0];
          int dy = now.y + dir[j][1];
          if (check(dx, dy)) {
            vis[dx][dy] = 1;
            ans[i]++;
            q.push(node(dx, dy, now.step - 1));
          }
        }
      }
    }
    if (!flag) break;
  }
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
