#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m, p, X, Y, G = 1, k;
  cin >> n >> m >> p;
  char C[n + 2][m + 2];
  int S[p + 1], s[p + 1];
  vector<pair<pair<int, int>, int>> T[p + 1], P[p + 1];
  for (int i = 1; i <= p; i++) {
    S[i] = 0;
    cin >> s[i];
  }
  for (int i = 0; i < n + 2; i++) {
    for (int y = 0; y < m + 2; y++) {
      C[i][y] = '#';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= m; y++) {
      cin >> C[i][y];
      if (C[i][y] != '.' && C[i][y] != '#') {
        T[C[i][y] - '0'].push_back({{i, y}, s[C[i][y] - '0']});
        S[C[i][y] - '0']++;
      }
    }
  }
  while (G == 1) {
    G = 0;
    for (int i = 0; i <= p; i++) {
      if (T[i].size() > 0) {
        G = 1;
        for (int y = 0; y < T[i].size(); y++) {
          k = T[i][y].second;
          Y = T[i][y].first.first;
          X = T[i][y].first.second;
          if (k > 0) {
            if (C[Y - 1][X] == '.') {
              S[i]++;
              C[Y - 1][X] = '0' + i;
              T[i].push_back({{Y - 1, X}, k - 1});
              P[i].push_back({{Y - 1, X}, k - 1});
            }
            if (C[Y + 1][X] == '.') {
              S[i]++;
              C[Y + 1][X] = '0' + i;
              T[i].push_back({{Y + 1, X}, k - 1});
              P[i].push_back({{Y + 1, X}, k - 1});
            }
            if (C[Y][X - 1] == '.') {
              S[i]++;
              C[Y][X - 1] = '0' + i;
              T[i].push_back({{Y, X - 1}, k - 1});
              P[i].push_back({{Y, X - 1}, k - 1});
            }
            if (C[Y][X + 1] == '.') {
              S[i]++;
              C[Y][X + 1] = '0' + i;
              T[i].push_back({{Y, X + 1}, k - 1});
              P[i].push_back({{Y, X + 1}, k - 1});
            }
          }
        }
      }
    }
    for (int i = 0; i <= p; i++) {
      T[i].clear();
      for (int y = 0; y < P[i].size(); y++) {
        k = P[i][y].second;
        if (k == 0) {
          T[i].push_back({{P[i][y].first.first, P[i][y].first.second}, s[i]});
        }
      }
      P[i].clear();
    }
  }
  for (int i = 1; i <= p; i++) {
    cout << S[i] << " ";
  }
  return 0;
}
