#include <bits/stdc++.h>
using namespace std;
int n, m, p;
string mp[1010];
bool used[1010][1010];
int spd[10];
inline bool check(complex<int> t) {
  int x = t.real(), y = t.imag();
  if (x < 0 || x >= n || y < 0 || y >= m) return 0;
  return mp[x][y] == '.';
}
complex<int> ways[] = {complex<int>(-1, 0), complex<int>(0, 1),
                       complex<int>(1, 0), complex<int>(0, -1)};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; ++i) cin >> spd[i];
  for (int i = 0; i < n; ++i) cin >> mp[i];
  vector<complex<int> > q[10];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mp[i][j] != '.' && mp[i][j] != '#')
        q[mp[i][j] - '0'].push_back({i, j});
  bool chg = 1;
  while (chg) {
    chg = 0;
    for (int i = 1; i <= p; ++i) {
      bool tchg = 1;
      for (int j = 0; j < spd[i] && tchg; ++j) {
        tchg = 0;
        vector<complex<int> > tmp;
        for (auto t : q[i]) {
          if (used[t.real()][t.imag()]) continue;
          used[t.real()][t.imag()] = 1;
          for (auto w : ways) {
            complex<int> now = t + w;
            if (check(now)) {
              mp[now.real()][now.imag()] = (char)(i + '0');
              tmp.push_back(now);
              chg = 1;
              tchg = 1;
            }
          }
        }
        q[i].swap(tmp);
      }
    }
  }
  int sum[10] = {};
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mp[i][j] != '.' && mp[i][j] != '#') sum[mp[i][j] - '0']++;
  for (int i = 1; i <= p; ++i) cout << sum[i] << " \n"[i == p];
}
