#include <bits/stdc++.h>
using namespace std;
void setupIO(const string &PROB) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ifstream infile(PROB + ".in");
  if (infile.good()) {
    freopen((PROB + ".in").c_str(), "r", stdin);
    freopen((PROB + ".out").c_str(), "w", stdout);
  }
}
int s[1000];
char grid[1000][1000];
int dist[1000][1000];
int n, m, p;
int main() {
  cin >> n >> m >> p;
  for (int i = 0; i < (p); i++) cin >> s[i];
  int ans[p];
  for (int i = 0; i < p; i++) ans[i] = 0;
  ;
  for (int i = 0; i < (1000); i++)
    for (int j = 0; j < (1000); j++) dist[i][j] = 0;
  ;
  queue<pair<int, int> > players[p];
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      cin >> grid[i][j];
      if ('1' <= grid[i][j] && grid[i][j] <= '9') {
        players[grid[i][j] - '1'].push(make_pair(i, j));
        ans[grid[i][j] - '1']++;
      }
    }
  }
  bool change = true;
  int iteration = 1;
  while (change) {
    change = false;
    for (int i = 0; i < (p); i++) {
      while (!players[i].empty()) {
        pair<int, int> next = players[i].front();
        if (dist[next.first][next.second] >= iteration * s[i]) break;
        players[i].pop();
        int dx[4] = {0, 1, 0, -1};
        int dy[4] = {1, 0, -1, 0};
        for (int j = 0; j < (4); j++) {
          pair<int, int> x = {next.first + dx[j], next.second + dy[j]};
          if (x.first < 0 || x.first >= n || x.second < 0 || x.second >= m ||
              grid[x.first][x.second] != '.')
            continue;
          grid[x.first][x.second] = '1' + i;
          ans[i]++;
          players[i].push(x);
          dist[x.first][x.second] = dist[next.first][next.second] + 1;
          change = true;
        }
      }
    }
    iteration++;
  }
  cout << ans[0];
  for (int i = 1; i < (p); i++) cout << " " << ans[i];
  cout << endl;
  return 0;
}
