#include <bits/stdc++.h>
const int NMAX = 1e3 + 100;
const int PMAX = 10;
struct pair {
  int x, y;
  pair(int x, int y) : x(x), y(y) {}
};
char field[NMAX][NMAX];
std::queue<pair> qs[PMAX];
std::vector<int> players;
int speed[PMAX], answer[PMAX];
int n, m, p;
bool way;
void preparetion() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
}
void init() { memset(field, '#', sizeof field); }
void get_data() {
  std::cin >> n >> m >> p;
  for (int i = 0; i < p; i++) {
    std::cin >> speed[i];
    players.push_back(i);
  }
  init();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      std::cin >> field[i][j];
      if (field[i][j] >= '1' && field[i][j] <= '9') {
        answer[field[i][j] - '0' - 1]++;
        qs[field[i][j] - '0' - 1].push(pair(i, j));
      }
    }
}
int d_x[] = {0, 0, -1, 1};
int d_y[] = {-1, 1, 0, 0};
void bfs(int cur_player) {
  for (int i = 0; !qs[cur_player].empty() && i < speed[cur_player]; i++) {
    std::queue<pair> tmp_q;
    while (!qs[cur_player].empty()) {
      pair cur = qs[cur_player].front();
      qs[cur_player].pop();
      for (int i = 0; i < 4; i++) {
        int to_x = cur.x + d_x[i], to_y = cur.y + d_y[i];
        if (field[to_x][to_y] == '.') {
          way = true;
          answer[cur_player]++;
          tmp_q.push(pair(to_x, to_y));
          field[to_x][to_y] = '0' + cur_player + 1;
        }
      }
    }
    qs[cur_player] = tmp_q;
  }
}
void print() {
  for (int i = 0; i < p; i++) std::cout << answer[i] << ' ';
}
void find_solution() {
  way = false;
  do {
    way = false;
    for (int i = 0; i < p; i++) bfs(i);
  } while (way);
}
int main() {
  preparetion();
  get_data();
  find_solution();
  print();
  return 0;
}
