#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
queue<pair<int, int> > q[20];
string s[1010];
vector<pair<int, int> > tmp[20];
int n, m, p, t[20], ans[20], now = 0;
int distt[1010][1010][20], dist[1010][1010][20];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
inline bool out(int x, int y) { return x < 0 || y < 0 || x >= n || y >= m; }
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> t[i];
  memset(distt, -1, sizeof(distt));
  memset(dist, -1, sizeof(dist));
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      if (isdigit(s[i][j])) {
        q[s[i][j] - '0'].push({i, j});
        distt[i][j][s[i][j] - '0'] = 0;
        dist[i][j][s[i][j] - '0'] = 0;
        ans[s[i][j] - '0']++;
      }
    }
  }
  while (true) {
    now++;
    bool is = false;
    for (int i = 1; i <= p; i++) {
      while (!q[i].empty()) {
        is = true;
        int x = q[i].front().first, y = q[i].front().second;
        bool ok = true;
        for (int j = 0; j < 4; j++) {
          int xx = x + dx[j], yy = y + dy[j];
          if (out(xx, yy) || isdigit(s[xx][yy]) || s[xx][yy] == '#') continue;
          s[xx][yy] = i + '0';
          dist[xx][yy][i] = dist[x][y][i] + 1;
          distt[xx][yy][i] = (dist[xx][yy][i] + t[i] - 1) / t[i];
          if (distt[xx][yy][i] > now) {
            dist[xx][yy][i] = distt[xx][yy][i] = -1;
            s[xx][yy] = '.';
            ok = false;
            break;
          }
          q[i].push({xx, yy});
          ans[i]++;
        }
        if (!ok) break;
        q[i].pop();
      }
    }
    if (!is) break;
  }
  for (int i = 1; i <= p; i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
