#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);
long long int modexp(long long int a, int b) {
  long long int t = 1;
  while (b != 0) {
    if (b % 2 == 1) t = (t * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return t % 1000000007;
}
int n = 1, m = 1, p = 1;
int ps[10];
long long int f = 1;
vector<vector<long long int>> v(10);
vector<vector<long long int>> ori(10);
vector<long long int> ne;
int ma[2000][2000];
int flag[1500][1500];
int ti[1500][1500];
int be[1500][1500];
int change(int num, int error) {
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      flag[i][j] = 0;
      if (be[i][j] == num) {
        be[i][j] = -1;
        ti[i][j] = 1000000000;
      }
    }
  for (i = 0; i < v[num].size(); i++) {
    int x = v[num][i] / 1000;
    int y = v[num][i] % 1000 + 1;
    be[x][y] = num;
    ti[x][y] = 0;
  }
  while (v[num].size() != 0) {
    for (i = 0; i < v[num].size(); i++) {
      int x = v[num][i] / 1000;
      int y = v[num][i] % 1000 + 1;
      int now = flag[x][y] + 1;
      int nt;
      nt = now / ps[num];
      if (now % ps[num] != 0) nt++;
      if (ma[x - 1][y] == 0 && x != 1) {
        if (flag[x - 1][y] == 0) {
          flag[x - 1][y] = flag[x][y] + 1;
          if (nt < ti[x - 1][y]) {
            if (be[x - 1][y] != -1) error = 1;
            ti[x - 1][y] = nt;
            be[x - 1][y] = num;
            ne.push_back((x - 1) * 1000 + y - 1);
          }
        }
      }
      if (ma[x + 1][y] == 0 && x != n) {
        if (flag[x + 1][y] == 0) {
          flag[x + 1][y] = flag[x][y] + 1;
          if (nt < ti[x + 1][y]) {
            if (be[x + 1][y] != -1) error = 1;
            ti[x + 1][y] = nt;
            be[x + 1][y] = num;
            ne.push_back((x + 1) * 1000 + y - 1);
          }
        }
      }
      if (ma[x][y - 1] == 0 && y != 1) {
        if (flag[x][y - 1] == 0) {
          flag[x][y - 1] = flag[x][y] + 1;
          if (nt < ti[x][y - 1]) {
            if (be[x][y - 1] != -1) error = 1;
            ti[x][y - 1] = nt;
            be[x][y - 1] = num;
            ne.push_back((x)*1000 + y - 2);
          }
        }
      }
      if (ma[x][y + 1] == 0 && y != m) {
        if (flag[x][y + 1] == 0) {
          if (nt < ti[x][y + 1]) {
            if (be[x][y + 1] != -1) error = 1;
            ti[x][y + 1] = nt;
            be[x][y + 1] = num;
            ne.push_back((x)*1000 + y);
          }
          flag[x][y + 1] = flag[x][y] + 1;
        }
      }
    }
    swap(v[num], ne);
    ne.clear();
  }
  return error;
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  int i, j;
  char s[2000];
  for (i = 1; i <= p; i++) {
    scanf("%d", &ps[i]);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      be[i][j] = -1;
      ti[i][j] = 1000000000;
    }
  }
  for (i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (j = 1; j <= m; j++) {
      if (s[j] == '.')
        ma[i][j] = 0;
      else if (s[j] == '#')
        ma[i][j] = -1;
      else {
        ma[i][j] = s[j] - '0';
        v[ma[i][j]].push_back(i * 1000 + j - f);
        ori[ma[i][j]].push_back(i * 1000 + j - f);
      }
    }
  }
  for (i = 1; i <= p; i++) {
    v[i].clear();
    for (j = 0; j < ori[i].size(); j++) v[i].push_back(ori[i][j]);
    int error = change(i, 0);
    if (error == 1) i = 0;
  }
  int sum[10] = {0};
  for (int i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (be[i][j] != -1) sum[be[i][j]]++;
    }
  }
  for (i = 1; i <= p; i++) printf("%d ", sum[i]);
  printf("\n");
  return 0;
}
