#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
} t;
queue<Point> q[10];
int cur = 0;
int ans[10];
int dc[4] = {0, 0, 1, -1};
int dr[4] = {-1, 1, 0, 0};
long long s[10], dis[1001][1001];
string a[1001];
int n, m;
vector<Point> v;
void get(int x) {
  v.clear();
  while (q[x].size()) {
    Point u = q[x].front();
    q[x].pop();
    if (dis[u.x][u.y] == s[x] * cur) {
      v.push_back(u);
      continue;
    }
    for (int i = 0; i < 4; i++) {
      int xx = u.x + dc[i];
      int yy = u.y + dr[i];
      if (xx >= 0 && xx < n && yy >= 0 && yy < m && a[xx][yy] == '.') {
        if (dis[xx][yy] > dis[u.x][u.y] + 1) {
          t.x = xx, t.y = yy;
          dis[xx][yy] = dis[u.x][u.y] + 1;
          a[xx][yy] = '0' + x;
          q[x].push(t);
        }
      }
    }
  }
  for (auto i : v) q[x].push(i);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int p;
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> s[i];
  memset(dis, 127, sizeof dis);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < a[i].size(); j++) {
      if ('1' <= a[i][j] && a[i][j] <= '9')
        t.x = i, t.y = j, q[a[i][j] - '0'].push(t), dis[i][j] = 0;
    }
  }
  while (true) {
    cur++;
    bool f = 0;
    for (int i = 1; i <= p; i++) {
      if (q[i].size()) get(i), f = 1;
    }
    if (f == 0) break;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i].size(); j++) {
      if ('1' <= a[i][j] && a[i][j] <= '9') ans[a[i][j] - '0']++;
    }
  }
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  return 0;
}
