#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1 << 29;
const int N = 4e4 + 5, M = 1e6 + 5;
char mp[1010][1010];
int ans[1010], semp, ve[1010];
int n, m, q;
int movx[4] = {1, -1, 0, 0};
int movy[4] = {0, 0, -1, 1};
void ini() {
  memset(ans, 0, sizeof(ans));
  memset(mp, 0, sizeof(mp));
  memset(ve, 0, sizeof(ve));
  semp = 0;
}
struct node {
  int x, y;
  int ve, ty;
  bool operator<(node x) const { return ve < x.ve; }
  node(int a, int b, int c, int d) {
    x = a;
    y = b;
    ve = c;
    ty = d;
  }
};
priority_queue<node> qe;
queue<node> tem;
void bfs() {
  int type = tem.front().ty;
  while (!tem.empty() && tem.front().ty == type) {
    qe.push(tem.front());
    tem.pop();
  }
  while (!qe.empty()) {
    node u = qe.top();
    qe.pop();
    for (int i = 0; i < 4; i++) {
      int nx = u.x + movx[i], ny = u.y + movy[i];
      if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
      if (mp[nx][ny] == '.') {
        mp[nx][ny] = type + '0';
        ans[type]++;
        semp--;
        if (u.ve - 1 == 0)
          tem.push(node(nx, ny, ve[type], u.ty));
        else
          qe.push(node(nx, ny, u.ve - 1, u.ty));
      }
    }
  }
  return;
}
vector<node> vc[1010];
int main() {
  ini();
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= q; i++) scanf("%d", &ve[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] >= '1' && mp[i][j] <= '9') {
        vc[mp[i][j] - '0'].push_back(
            node(i, j, ve[mp[i][j] - '0'], mp[i][j] - '0'));
        ans[mp[i][j] - '0']++;
      }
      if (mp[i][j] == '.') semp++;
    }
  }
  for (int i = 1; i <= q; i++)
    for (int j = 0; j < vc[i].size(); j++) tem.push(vc[i][j]);
  while (!tem.empty() && semp) bfs();
  for (int i = 1; i <= q; i++) {
    printf("%d", ans[i]);
    if (i != q) printf(" ");
  }
  return 0;
}
