#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, p;
  cin >> n >> m >> p;
  int movement[10];
  for (int i = 1; i <= p; ++i) {
    cin >> movement[i];
  }
  static char arr[1001][1001];
  static int freq[10];
  queue<pair<int, int>> q[10];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      if (isdigit(c)) {
        int p = c - '0';
        q[p].push({i, j});
        ++freq[p];
        arr[i][j] = p;
      } else {
        arr[i][j] = c;
      }
    }
    cin.ignore();
  }
  bool is_modified;
  do {
    is_modified = false;
    for (int i = 1; i <= p; ++i) {
      for (int mv = movement[i]; !q[i].empty() && mv; --mv) {
        int cnt = q[i].size();
        while (cnt--) {
          auto cur = q[i].front();
          q[i].pop();
          for (int d = 0; d < 4; ++d) {
            const int dx[] = {1, 0, -1, 0};
            const int dy[] = {0, -1, 0, 1};
            int x = cur.first + dx[d];
            int y = cur.second + dy[d];
            if (x < 1 || x > n) {
              continue;
            }
            if (y < 1 || y > m) {
              continue;
            }
            if (arr[x][y] != '.') {
              continue;
            }
            is_modified = true;
            arr[x][y] = i;
            q[i].push({x, y});
            ++freq[i];
          }
        }
      }
    }
  } while (is_modified);
  for (int i = 1; i <= p; ++i) {
    cout << freq[i] << ' ';
  }
  return 0;
}
