#include <bits/stdc++.h>
using namespace std;
int LIM = 2e5 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long int> steps(k + 1, 0);
  for (int i = 1; i <= k; i++) cin >> steps[i];
  vector<string> matrix(n + 1);
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    s = "a" + s;
    matrix[i] = s;
  }
  vector<vector<pair<long long int, long long int> > > first(k + 1);
  vector<vector<long long int> > conquer(n + 1,
                                         vector<long long int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (matrix[i][j] != '.' && matrix[i][j] != '#') {
        first[matrix[i][j] - '1' + 1].push_back(
            pair<long long int, long long int>(i, j));
        conquer[i][j] = matrix[i][j] - '1' + 1;
      }
    }
  }
  vector<long long int> ans(k + 1, 0);
  while (true) {
    bool move = false;
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= steps[i]; j++) {
        vector<pair<long long int, long long int> > next;
        vector<pair<long long int, long long int> > frontier = first[i];
        for (int j = 0; j < frontier.size(); j++) {
          pair<long long int, long long int> node = frontier[j];
          int x = node.first, y = node.second;
          if (x + 1 <= n && matrix[x + 1][y] == '.' && conquer[x + 1][y] == 0) {
            conquer[x + 1][y] = i;
            next.push_back(pair<long long int, long long int>(x + 1, y));
          }
          if (x - 1 >= 1 && matrix[x - 1][y] == '.' && conquer[x - 1][y] == 0) {
            conquer[x - 1][y] = i;
            next.push_back(pair<long long int, long long int>(x - 1, y));
          }
          if (y + 1 <= m && matrix[x][y + 1] == '.' && conquer[x][y + 1] == 0) {
            conquer[x][y + 1] = i;
            next.push_back(pair<long long int, long long int>(x, y + 1));
          }
          if (y - 1 >= 0 && matrix[x][y - 1] == '.' && conquer[x][y - 1] == 0) {
            conquer[x][y - 1] = i;
            next.push_back(pair<long long int, long long int>(x, y - 1));
          }
        }
        first[i] = next;
        if (first[i].size() > 0) move = true;
        if (first[i].size() == 0) break;
      }
    }
    if (move == false) break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (matrix[i][j] != '#') ans[conquer[i][j]]++;
    }
  }
  for (int i = 1; i <= k; i++) cout << ans[i] << " ";
  return 0;
}
