#include <bits/stdc++.h>
using namespace std;
string str[1010];
int visited[1010][1010], n, m, p;
map<int, int> mp;
map<char, int> mp1;
vector<pair<int, int>> q[1010], q1;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void BFS() {
  while (1) {
    int flag = 0;
    for (int i = 1; i <= p; i++) {
      for (int j = 0; j < mp[i]; j++) {
        q1.clear();
        for (int k = 0; k < q[i].size(); k++) {
          for (int k1 = 0; k1 < 4; k1++) {
            int u = q[i][k].first + dx[k1];
            int v = q[i][k].second + dy[k1];
            if ((u >= 0 && u < n) && (v >= 0 && v < m)) {
              if (visited[u][v] == 0 && str[u][v] != '#') {
                visited[u][v] = 1;
                q1.push_back(make_pair(u, v));
                str[u][v] = i + '0';
                flag = 1;
              }
            }
          }
        }
        if (q1.size() == 0) {
          break;
        } else {
          q[i] = q1;
        }
      }
    }
    if (flag == 0) break;
  }
}
int main() {
  cin >> n >> m >> p;
  for (int i = 0; i < p; i++) {
    int x;
    cin >> x;
    mp[i + 1] = x;
  }
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  memset(visited, 0, sizeof(visited));
  for (int i = 1; i <= p; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if ((str[j][k] - '0') == i) {
          q[i].push_back(make_pair(j, k));
          visited[j][k] = 1;
        }
      }
    }
  }
  BFS();
  for (int j = 0; j < n; j++) {
    for (int k = 0; k < m; k++) {
      mp1[str[j][k]]++;
    }
  }
  for (int i = 1; i <= p; i++) {
    char x = i + '0';
    cout << mp1[x] << " ";
  }
  cout << endl;
}
