#include <bits/stdc++.h>
using namespace std;
char g[1000][1000];
int n, m, p, s[10];
bool activo[10];
int suma[10];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
bool esValido(int a, int b) { return (0 <= a && a < n && 0 <= b && b < m); }
struct par {
  int x, y;
};
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= p; i++) {
    scanf("%d", &s[i]);
    activo[i] = true;
  }
  for (int i = 0; i < n; i++) scanf(" %s", &g[i][0]);
  queue<par> cola[p + 1];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if ('1' <= g[i][j] && g[i][j] <= '9') cola[g[i][j] - '0'].push({i, j});
  while (true) {
    int exp = 0;
    for (int i = 1; i <= p; i++) {
      if (activo[i]) {
        int res = 0;
        for (int z = 0; z < s[i]; z++) {
          int cant = 0;
          int tamCola = cola[i].size();
          while (tamCola--) {
            auto k = cola[i].front();
            cola[i].pop();
            for (int j = 0; j < 4; j++) {
              int x = k.x + dx[j];
              int y = k.y + dy[j];
              if (esValido(x, y) && g[x][y] == '.') {
                exp++;
                cant++;
                res++;
                g[x][y] = i + '0';
                cola[i].push({x, y});
              }
            }
          }
          if (cant == 0) {
            break;
          }
        }
        if (res == 0) {
          activo[i] = false;
        }
      }
    }
    if (exp == 0) break;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if ('1' <= g[i][j] && g[i][j] <= '9') suma[g[i][j] - '0']++;
  for (int i = 1; i <= p; i++) printf("%d ", suma[i]);
  printf("\n");
  return 0;
}
