#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int sp[15], prenum[15];
char mpa[int(1e3 + 7)][int(1e3 + 7)];
bool vis[int(1e3 + 7)][int(1e3 + 7)], go[15];
vector<pair<int, int> > vec[15];
bool fp, flag;
const int dir[][2] = {1, 0, 0, 1, -1, 0, 0, -1};
struct Node {
  int x, y, s;
  Node(int _x = 0, int _y = 0, int _s = 0) : x(_x), y(_y), s(_s) {}
};
void bfs(int u) {
  queue<Node> q;
  for (int i = vec[u].size() - prenum[u]; i < vec[u].size(); i++) {
    int fi = vec[u][i].first, se = vec[u][i].second;
    vis[fi][se] = true;
    q.push(Node(fi, se, 0));
  }
  int num = 0;
  while (!q.empty()) {
    Node now = q.front();
    q.pop();
    int xx = now.x, yy = now.y;
    if (now.s == sp[u]) {
      prenum[u] = num;
      return;
    }
    for (int k = 0; k < 4; k++) {
      int nx = xx + dir[k][0];
      int ny = yy + dir[k][1];
      if (nx < 1 || nx > n || ny < 1 || ny > m || vis[nx][ny])
        continue;
      else if (mpa[nx][ny] == '.') {
        mpa[nx][ny] = u + '0';
        vec[u].push_back(pair<int, int>(nx, ny));
        vis[nx][ny] = true;
        flag = true;
        num++;
        q.push(Node(nx, ny, now.s + 1));
      }
    }
  }
  prenum[u] = num;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; i++) scanf("%d", &sp[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mpa[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (mpa[i][j] >= '1' && mpa[i][j] <= p + '0') {
        vec[mpa[i][j] - '0'].push_back(pair<int, int>(i, j));
      }
    }
  }
  for (int i = 1; i <= p; i++) prenum[i] = vec[i].size();
  memset(vis, false, sizeof(vis));
  memset(go, true, sizeof(go));
  while (true) {
    fp = false;
    for (int i = 1; i <= p; i++) {
      if (!go[i]) continue;
      if (go[i]) flag = false, bfs(i);
      if (!flag) go[i] = false;
      if (flag) fp = true;
    }
    if (!fp) break;
  }
  for (int i = 1; i <= p; i++) {
    i == p ? printf("%d\n", vec[i].size()) : printf("%d ", vec[i].size());
  }
}
