#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e3 + 5;
const int INF = (int)1e9;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
queue<pair<int, int> > q[10];
int d[10][MAXN][MAXN];
int col[MAXN][MAXN];
char s[MAXN][MAXN];
int speed[MAXN];
int ans[MAXN];
int n, m, p;
void bfs() {
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < m; ++y) {
      col[x][y] = -1;
    }
  }
  for (int i = 1; i <= p; ++i) {
    for (int x = 0; x < n; ++x) {
      for (int y = 0; y < m; ++y) {
        d[i][x][y] = -1;
        if (s[x][y] == i + '0') {
          q[i].push(make_pair(x, y));
          d[i][x][y] = 0;
          col[x][y] = i;
        }
      }
    }
  }
  vector<pair<int, int> > colored, mem;
  while (1) {
    bool leave = 1;
    for (int i = 1; i <= p; ++i) {
      colored.clear();
      mem.clear();
      leave &= q[i].empty();
      while (!q[i].empty()) {
        int cx = q[i].front().first;
        int cy = q[i].front().second;
        q[i].pop();
        if (d[i][cx][cy] == speed[i]) {
          mem.push_back(make_pair(cx, cy));
          continue;
        }
        for (int dir = 0; dir < 4; ++dir) {
          int nx = cx + dx[dir];
          int ny = cy + dy[dir];
          if (nx < 0 || nx >= n || ny < 0 || ny >= m) {
            continue;
          }
          if (s[nx][ny] == '#' || col[nx][ny] != -1) {
            continue;
          }
          if (d[i][nx][ny] == -1) {
            d[i][nx][ny] = d[i][cx][cy] + 1;
            col[nx][ny] = col[cx][cy];
            colored.push_back(make_pair(nx, ny));
            q[i].push(make_pair(nx, ny));
          }
        }
      }
      for (auto it : colored) {
        d[i][it.first][it.second] = 0;
      }
      for (auto it : mem) {
        q[i].push(it);
      }
    }
    if (leave) {
      break;
    }
  }
}
void solve() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= p; ++i) {
    scanf("%d", &speed[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  bfs();
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < m; ++y) {
      if (col[x][y] != -1) {
        ++ans[col[x][y]];
      }
    }
  }
  for (int i = 1; i <= p; ++i) {
    printf("%d ", ans[i]);
  }
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
