#include <bits/stdc++.h>
using namespace std;
struct data1 {
  long long fr, sc;
};
struct data2 {
  long long aa, bb, cc;
};
bool aacmp(const data2& A, const data2& B) { return A.aa < B.aa; }
vector<string> vst;
vector<data2> vdt;
long long vis[1002][1002], ext[1002][1002], ans[15], ara[15], sz = 0;
long long fx[4] = {1, -1, 0, 0}, fy[4] = {0, 0, 1, -1};
void bfs(long long n, long long m) {
  sort(vdt.begin(), vdt.end(), aacmp);
  data2 dt;
  data1 tt, rr;
  queue<data1> qdt, qt;
  long long i, j, k, x, y, z, a, b, c, e, d, u, v, lp, ax, by, w, o, g, h, cnt;
  for (i = 0; i < sz; i++) {
    a = vdt[i].bb;
    b = vdt[i].cc;
    tt.fr = a;
    tt.sc = b;
    qdt.push(tt);
  }
  while (!qdt.empty()) {
    cnt = 0;
    w;
    while (1) {
      tt = qdt.front();
      a = tt.fr;
      b = tt.sc;
      if (cnt == 0) {
        d = vis[a][b];
        x = ara[d];
        cnt++;
      } else {
        o = vis[a][b];
        if (o != d) break;
      }
      qt.push(tt);
      ext[a][b] = 0;
      qdt.pop();
      if (qdt.size() == 0) break;
    }
    while (!qt.empty()) {
      tt = qt.front();
      qt.pop();
      g = tt.fr;
      h = tt.sc;
      for (i = 0; i < 4; i++) {
        ax = g + fx[i];
        by = h + fy[i];
        if (ax >= 0 && ax <= n - 1 && by >= 0 && by <= m - 1) {
          if (vst[ax][by] != '#' && vis[ax][by] == 0) {
            ext[ax][by] = ext[g][h] + 1;
            if (ext[ax][by] == x) {
              tt.fr = ax;
              tt.sc = by;
              qdt.push(tt);
              vis[ax][by] = d;
              ans[d]++;
            } else if (ext[ax][by] < x) {
              tt.fr = ax;
              tt.sc = by;
              qt.push(tt);
              vis[ax][by] = d;
              ans[d]++;
            }
          }
        }
      }
    }
  }
}
int main() {
  long long n, m, p, i, j, a, b, c;
  char s[1004];
  string str;
  data2 ad;
  scanf("%lld %lld %lld", &n, &m, &p);
  for (i = 1; i <= p; i++) {
    scanf("%lld", &a);
    ara[i] = a;
  }
  for (i = 0; i < n; i++) {
    scanf("%s", s);
    str = string(s);
    vst.push_back(str);
    for (j = 0; j < m; j++) {
      if (str[j] != '.' && str[j] != '#') {
        a = str[j] - '0';
        vis[i][j] = a;
        ans[a]++;
        ad.aa = a;
        ad.bb = i;
        ad.cc = j;
        vdt.push_back(ad);
        sz++;
      }
    }
  }
  bfs(n, m);
  for (i = 1; i <= p; i++) {
    printf("%lld ", ans[i]);
  }
  return 0;
}
