#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, M = 1e9 + 7;
int n, m, p, ans[N], vis[N][N], s[N];
char a[N][N];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
queue<pair<int, pair<int, int>>> q[N];
bool check(int x, int y) {
  if (vis[x][y]) return true;
  if (x < 0 || y < 0 || x == n || y == m) return true;
  if (a[x][y] == '#') return true;
  return false;
}
void bfs(int p) {
  queue<pair<int, pair<int, int>>> newQ;
  while (q[p].size()) {
    pair<int, pair<int, int>> cur = q[p].front();
    q[p].pop();
    for (int i = 0; i < 4; i++) {
      int nx = cur.first + dx[i];
      int ny = cur.second.first + dy[i];
      if (check(nx, ny)) continue;
      if (cur.second.second == s[p]) {
        newQ.push({cur.first, {cur.second.first, 0}});
      } else {
        vis[nx][ny] = p;
        q[p].push({nx, {ny, cur.second.second + 1}});
      }
    }
  }
  q[p] = newQ;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; i++) scanf("%d", &s[i]);
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
    for (int j = 0; j < m; ++j) {
      int x = a[i][j] - '0';
      if (x >= 1 && x <= 10) {
        vis[i][j] = x;
        q[x].push({i, {j, 0}});
      }
    }
  }
  while (1) {
    int f = 0;
    for (int i = 1; i <= p; i++) {
      f += (q[i].size());
    }
    if (!f) break;
    for (int i = 1; i <= p; i++) {
      bfs(i);
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      ans[vis[i][j]]++;
    }
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
}
