#include <bits/stdc++.h>
using namespace std;
const int PI = acos(-1);
const int maxn = 1100;
const int INF = 0x3f3f3f3f;
int n, m, p;
struct node {
  int x, y, t;
  node(int x, int y, int t) : x(x), y(y), t(t) {}
};
char grid[maxn][maxn];
int s[maxn], vis[maxn][maxn];
queue<node> q1[maxn];
queue<node> q2[maxn];
int dirx[4] = {0, 0, 1, -1};
int diry[4] = {1, -1, 0, 0};
int expand;
void BFS(int x) {
  expand = 0;
  while (!q1[x].empty()) {
    node temp = q1[x].front();
    q1[x].pop();
    temp.t = 0;
    q2[x].push(temp);
  }
  while (!q2[x].empty()) {
    node temp = q2[x].front();
    q2[x].pop();
    if (temp.t == s[x]) {
      q1[x].push(temp);
      continue;
    }
    for (int i = 0; i < 4; i++) {
      int xx, yy;
      xx = temp.x + dirx[i];
      yy = temp.y + diry[i];
      if (!vis[xx][yy] && xx >= 0 && xx < n && yy >= 0 && yy < m &&
          grid[xx][yy] != '#' && temp.t + 1 <= s[x]) {
        expand++;
        q2[x].push(node(xx, yy, temp.t + 1));
        vis[xx][yy] = x;
      }
    }
  }
  return;
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= p; i++) scanf("%d", &s[i]);
  for (int i = 0; i < n; i++) scanf("%s", grid[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] >= '0' && grid[i][j] <= '9') {
        vis[i][j] = grid[i][j] - '0';
        q1[grid[i][j] - '0'].push(node(i, j, 0));
      }
    }
  }
  while (1) {
    int move = 0;
    for (int i = 1; i <= p; i++) {
      BFS(i);
      move += expand;
    }
    if (move == 0) break;
  }
  int count[maxn];
  memset(count, 0, sizeof(count));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      count[vis[i][j]]++;
    }
  }
  for (int i = 1; i <= p; i++) printf("%d ", count[i]);
}
