#include <bits/stdc++.h>
using namespace std;
const int MX = 3 * 1e5 + 50;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
struct Position {
  int x, y, id, v;
};
queue<Position> q;
vector<Position> pos[15];
int v[MX], ans[15];
int h, w, n, len = 0;
char mp[1050][1050];
bool dge(int x, int y) {
  if (x >= 1 && x <= w && y >= 1 && y <= h && mp[y][x] == '.') return true;
  return false;
}
void bfs() {
  queue<Position> qq;
  Position qt = q.front();
  while (q.front().id == qt.id) {
    qt = q.front();
    q.pop();
    qq.push(qt);
  }
  while (!qq.empty()) {
    qt = qq.front();
    qq.pop();
    for (int i = 0; i < 4; i++) {
      int x = qt.x + dx[i];
      int y = qt.y + dy[i];
      if (dge(x, y)) {
        mp[y][x] = qt.id;
        if (qt.v + 1 == v[qt.id]) {
          q.push(Position{x, y, qt.id, 0});
        } else
          qq.push(Position{x, y, qt.id, qt.v + 1});
        ans[qt.id]++;
      }
    }
    if (qq.empty() && !q.empty()) {
      qt.id = -1;
      while (qt.id == -1 || q.front().id == qt.id) {
        qt = q.front();
        q.pop();
        qq.push(qt);
        if (q.empty()) break;
      }
    }
  }
}
int main() {
  while (scanf("%d%d%d", &h, &w, &n) != EOF) {
    while (!q.empty()) q.pop();
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i <= n; i++) scanf("%d", v + i);
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        scanf(" %c", &mp[i][j]);
        if (mp[i][j] >= '1' && mp[i][j] <= '9') {
          Position temp = {j, i, mp[i][j] - '0'};
          temp.v = 0;
          pos[mp[i][j] - '0'].push_back(temp);
          ans[mp[i][j] - '0']++;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < pos[i].size(); j++) {
        q.push(pos[i][j]);
      }
    }
    bfs();
    for (int i = 1; i <= n; i++)
      if (i == n)
        printf("%d\n", ans[i]);
      else
        printf("%d ", ans[i]);
  }
}
