#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int inf = 2e9 + 100;
const int mod = 1e9 + 7;
struct Z {
  int x, y, z;
};
int a[10], n, m, p;
;
string s[maxn];
bool D0(Z a, Z b) { return a.z < b.z; }
queue<Z> q[10];
pair<int, int> dx[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void bfs() {
  while (1) {
    bool f = 1;
    for (int i = 1; i <= p; ++i) {
      if (q[i].empty())
        continue;
      else
        f = 0;
      queue<Z> nq;
      while (!q[i].empty()) {
        Z v = q[i].front();
        q[i].pop();
        for (auto j : dx) {
          Z to = {v.x + j.first, v.y + j.second, v.z - 1};
          if (to.x >= 0 && to.x < m && to.y >= 0 && to.y < n &&
              s[to.y][to.x] == '.') {
            s[to.y][to.x] = i + '0';
            if (to.z)
              q[i].push(to);
            else
              nq.push({to.x, to.y, a[i - 1]});
          }
        }
      }
      swap(nq, q[i]);
    }
    if (f) break;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> p;
  for (int i = 0; i < p; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> s[i];
  vector<Z> st;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] >= '0' && s[i][j] <= '9')
        q[s[i][j] - '0'].push({j, i, a[s[i][j] - '0' - 1]});
  bfs();
  vector<int> ans(p, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      if (s[i][j] >= '0' && s[i][j] <= '9') ans[s[i][j] - '1']++;
  }
  for (int i = 0; i < p; ++i) cout << ans[i] << " ";
  return 0;
}
