#include <bits/stdc++.h>
using namespace std;
const double EPS = (double)1e-9;
const double PI = (double)acos(-1.0);
int irand(int lo, int hi) {
  return (((double)rand()) / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
string toString(long long x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
long long toNumber(string S) {
  long long ret;
  sscanf(S.c_str(), "%lld", &ret);
  return ret;
}
const int INF = (int)2e9;
const long long MOD = (long long)1e9 + 7;
const int mx[] = {-1, 0, 1, 0};
const int my[] = {0, -1, 0, 1};
char s[1005][1005];
queue<pair<int, int> > bfs[15];
int main() {
  for (int i = 0; i < 13; i++)
    while (!bfs[i].empty()) bfs[i].pop();
  int n, m, p;
  scanf("%d %d %d", &n, &m, &p);
  int speed[15];
  for (int i = 1; i <= p; i += 1) scanf("%d", speed + i);
  for (int i = 1; i <= n; i += 1) scanf("%s", s[i] + 1);
  for (int i = 0; i <= n + 1; i += 1) s[i][0] = s[i][m + 1] = '#';
  for (int j = 0; j <= m + 1; j += 1) s[0][j] = s[n + 1][j] = '#';
  for (int i = 1; i <= n; i += 1)
    for (int j = 1; j <= m; j += 1)
      for (int k = 1; k <= p; k += 1) {
        if (s[i][j] == '0' + k) bfs[k].push(make_pair(i, j));
      }
  int res[15];
  for (int i = 0; i < 13; i++) res[i] = 0;
  for (int flag = 1; flag;) {
    flag = 0;
    for (int i = 1; i <= p; i += 1)
      for (int _speed = 0; _speed < speed[i]; _speed++) {
        int sz = (int)bfs[i].size();
        if (sz == 0) break;
        for (int step = 0; step < sz; step++) {
          pair<int, int> pos = bfs[i].front();
          bfs[i].pop();
          res[i]++;
          for (int j = 0; j < 4; j++) {
            pair<int, int> pot =
                make_pair(pos.first + mx[j], pos.second + my[j]);
            if (s[pot.first][pot.second] != '.') continue;
            s[pot.first][pot.second] = '0' + i;
            bfs[i].push(pot);
          }
        }
        flag = 1;
      }
  }
  for (int i = 1; i <= p; i += 1) printf("%d%c", res[i], " \n"[i == p]);
  return 0;
}
