#include <bits/stdc++.h>
using namespace std;
const int N = 1 * 1000 + 1, P = 10;
int n, m, vis[N][N], cnt, ans[P], p, s[P];
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
queue<pair<int, int>> Q[P];
void bfs(int cur) {
  for (int i = 0; i < s[cur] && Q[cur].size(); i++)
    for (int j = Q[cur].size(); j > 0; j--) {
      int x = Q[cur].front().first;
      int y = Q[cur].front().second;
      Q[cur].pop();
      for (int k = 0; k < 4; k++) {
        int tx = x + dx[k], ty = y + dy[k];
        if (~tx && ~ty && tx - n && ty - m && !vis[tx][ty]) {
          vis[tx][ty] = cur;
          ans[cur]++, cnt++;
          Q[cur].push({tx, ty});
        }
      }
    }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char a;
      cin >> a;
      if (a == '#')
        vis[i][j] = -1, cnt++;
      else if (a != '.') {
        vis[i][j] = a - '0';
        Q[a - '0'].push({i, j});
        ans[a - '0']++, cnt++;
      }
    }
  for (int j = 0; j < n * m; j++)
    for (int i = 1; i <= p; i++) bfs(i);
  for (int i = 1; i <= p; i++) cout << ans[i] << endl;
}
