#include <bits/stdc++.h>
using namespace std;
const int MAXX = 1e3 + 10, N = 12, inf = 1e7 + 10;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m, p, a[N], dis[MAXX][MAXX], ans[N];
string s[MAXX];
bool vis[MAXX][MAXX];
deque<pair<int, int>> dq[N];
bool Ok() {
  for (int i = 1; i <= p; i++)
    if (dq[i].size()) return 1;
  return 0;
}
bool isValid(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m && s[x][y] == '.' && !vis[x][y]);
}
void bfs(int v) {
  deque<pair<int, int>> dq2 = dq[v];
  while (dq2.size())
    dis[dq2.front().first][dq2.front().second] = 0, dq2.pop_front();
  while (dq[v].size()) {
    int x = dq[v].front().first, y = dq[v].front().second;
    s[x][y] = v + '0';
    if (dis[x][y] == a[v]) return;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (isValid(nx, ny))
        dq[v].push_back({nx, ny}), s[nx][ny] = s[x][y],
                                   dis[nx][ny] = dis[x][y] + 1;
    }
    dq[v].pop_front();
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] >= '1' && s[i][j] <= '9')
        dq[(s[i][j] - '0')].push_back({i, j});
  while (Ok())
    for (int i = 1; i <= p; i++) bfs(i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] >= '1' && s[i][j] <= '9') ans[s[i][j] - '0']++;
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  return cout << endl, 0;
}
