#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
char ma[1005][1005];
vector<pair<pair<int, int>, int> > v[20];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}, s[20], vis[1005][1005],
    ans[20], n, m, p;
bool bfs(int id) {
  queue<pair<pair<int, int>, int> > q;
  for (auto& i : v[id]) q.push(i);
  v[id].clear();
  while (!q.empty()) {
    pair<pair<int, int>, int> tmp = q.front();
    q.pop();
    int d = tmp.second, x = tmp.first.first, y = tmp.first.second;
    if (d == s[id]) {
      v[id].push_back(make_pair(make_pair(x, y), 0));
      continue;
    }
    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i], ny = y + dy[i];
      if (0 <= nx && nx < n && 0 <= ny && ny < m && ma[nx][ny] != '#' &&
          !vis[nx][ny])
        q.push(make_pair(make_pair(nx, ny), d + 1)), vis[nx][ny] = id;
    }
  }
  return int(v[id].size());
}
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= p; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i) scanf("%s", ma[i]);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (isdigit(ma[i][j]))
        v[ma[i][j] - '0'].push_back(make_pair(make_pair(i, j), 0)),
            vis[i][j] = ma[i][j] - '0';
    }
  }
  bool f = 1;
  while (f) {
    f = 0;
    for (int i = 1; i <= p; ++i)
      if (bfs(i)) f = 1;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) ans[vis[i][j]]++;
  for (int i = 1; i <= p; ++i) cout << ans[i] << " ";
  return 0;
}
