#include <bits/stdc++.h>
using namespace std;
int n, m, p;
char matrix[1000][1000];
int expansion[10];
int controlled[10];
int max_layer[10];
vector<pair<int, int> > starters[10];
int main() {
  cin >> n >> m >> p;
  queue<pair<pair<int, int>, int> > q;
  for (int i = 0; i < p; i++) {
    cin >> expansion[i];
    controlled[i] = 0;
    max_layer[i] = expansion[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> matrix[i][j];
      if (matrix[i][j] != '.' && matrix[i][j] != '#') {
        int player = matrix[i][j] - '1';
        starters[player].push_back(make_pair(i, j));
        controlled[player]++;
      }
    }
  }
  bool moved = true;
  while (moved) {
    moved = false;
    for (int i = 0; i < p; i++) {
      for (int j = 0; j < starters[i].size(); j++)
        q.push(make_pair(starters[i][j], 0));
      starters[i].clear();
      while (!q.empty()) {
        int x = q.front().first.first;
        int y = q.front().first.second;
        int layer = q.front().second;
        q.pop();
        pair<int, int> locs[4] = {make_pair(x + 1, y), make_pair(x - 1, y),
                                  make_pair(x, y + 1), make_pair(x, y - 1)};
        for (pair<int, int> loc : locs) {
          if (loc.first < 0 || loc.first > n - 1 || loc.second < 0 ||
              loc.second > m - 1)
            continue;
          if (matrix[loc.first][loc.second] != '.') continue;
          moved = true;
          controlled[i]++;
          matrix[loc.first][loc.second] = (i + '1');
          if (layer >= expansion[i] - 1) {
            starters[i].push_back(make_pair(loc.first, loc.second));
          } else {
            q.push(make_pair(make_pair(loc.first, loc.second), layer + 1));
          }
        }
      }
    }
  }
  for (int i = 0; i < p; i++) cout << controlled[i] << " ";
  cout << endl;
  return 0;
}
