#include <bits/stdc++.h>
using namespace std;
int n, m, p;
vector<int> s(10);
vector<string> grid;
vector<vector<pair<int, int> > > last(10);
int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};
bool check(vector<bool>& don) {
  for (int i = 1; i <= p; i++)
    if (!don[i]) return 1;
  return 0;
}
void color(int i) {
  vector<pair<int, int> > nex;
  for (pair<int, int> el : last[i]) {
    for (int j = 0; j < 4; j++) {
      int xx = el.first + x[j], yy = el.second + y[j];
      if (xx >= n || yy >= m || xx < 0 || yy < 0) continue;
      if (grid[xx][yy] == '.') {
        grid[xx][yy] = char('0' + i);
        nex.push_back({xx, yy});
      }
    }
  }
  last[i] = nex;
}
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    grid.push_back(temp);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] >= '1' && grid[i][j] <= '9') {
        last[grid[i][j] - '0'].push_back({i, j});
      }
    }
  }
  vector<bool> don(10, 0);
  int i = 1;
  while (check(don)) {
    for (int j = 0; j < s[i]; j++) {
      color(i);
      if (last[i].size() == 0) {
        don[i] = 1;
        break;
      }
    }
    i++;
    if (i > p) {
      i = 1;
    }
  }
  vector<int> cnt(10, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] <= '9' && grid[i][j] >= '0') cnt[grid[i][j] - '0']++;
    }
  }
  for (int i = 1; i <= p; i++) {
    cout << cnt[i] << ' ';
  }
  cout << "\n";
  return 0;
}
