#include <bits/stdc++.h>
using namespace std;
int dist[1005][1005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m, p;
  cin >> n >> m >> p;
  vector<long long> s(p + 1);
  for (int i = 1; i <= p; i++) cin >> s[i];
  queue<pair<int, int> > q[p + 1];
  for (int i = 0; i < 1005; i++)
    for (int j = 0; j < 1005; j++) dist[i][j] = 1000000009;
  char M[n + 5][m + 5];
  int free = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> M[i][j];
      if (M[i][j] >= '1' && M[i][j] <= '9') {
        q[M[i][j] - '0'].push(make_pair(i, j));
        dist[i][j] = 0;
      } else if (M[i][j] == '.')
        free++;
    }
  long long time = 1;
  set<int> ss;
  for (int i = 1; i <= p; i++) ss.insert(i);
  int x, y;
  pair<int, int> temp;
  while (free > 0 && !ss.empty()) {
    for (int i = 1; i <= p && free > 0 && !ss.empty(); i++) {
      if (q[i].empty()) ss.erase(i);
      long long mx = time * s[i];
      while (!q[i].empty() && free > 0) {
        temp = q[i].front();
        if (dist[temp.first][temp.second] >= mx) break;
        q[i].pop();
        x = temp.first;
        y = temp.second;
        if (x > 0 && M[x - 1][y] == '.') {
          dist[x - 1][y] = dist[x][y] + 1;
          q[i].push(make_pair(x - 1, y));
          M[x - 1][y] = (char)(i + '0');
          free--;
        }
        if (x < n - 1 && M[x + 1][y] == '.') {
          dist[x + 1][y] = dist[x][y] + 1;
          q[i].push(make_pair(x + 1, y));
          M[x + 1][y] = (char)(i + '0');
          free--;
        }
        if (y < m - 1 && M[x][y + 1] == '.') {
          dist[x][y + 1] = dist[x][y] + 1;
          q[i].push(make_pair(x, y + 1));
          M[x][y + 1] = (char)(i + '0');
          free--;
        }
        if (y > 0 && M[x][y - 1] == '.') {
          dist[x][y - 1] = dist[x][y] + 1;
          q[i].push(make_pair(x, y - 1));
          M[x][y - 1] = (char)(i + '0');
          free--;
        }
      }
      if (q[i].empty()) ss.erase(i);
    }
    time++;
  }
  vector<int> ans(p, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (M[i][j] >= '1' && M[i][j] <= '9') {
        x = M[i][j] - '1';
        ans[x]++;
      }
    }
  for (auto it = ans.begin(); it != ans.end(); it++) cout << *it << ' ';
  cout << endl;
  ;
}
