#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
int step[9];
int cnt[9];
bool vis[MAX]{false};
char arr[MAX];
int tick[MAX];
int dis[MAX];
vector<int> start[9];
vector<int> adj[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, p;
  cin >> n >> m >> p;
  for (int i = 0; i < p; i++) cin >> step[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int index = i * m + j;
      tick[index] = -1;
      dis[index] = INT_MAX;
      cin >> arr[index];
      if (arr[index] != '#' && arr[index] != '.')
        start[arr[index] - '1'].push_back(index);
      if (i - 1 >= 0) adj[index].push_back((i - 1) * m + j);
      if (i + 1 < n) adj[index].push_back((i + 1) * m + j);
      if (j - 1 >= 0) adj[index].push_back(i * m + j - 1);
      if (j + 1 < m) adj[index].push_back(i * m + j + 1);
    }
  }
  queue<pair<int, queue<int>>> que;
  for (int i = 0; i < p; i++) {
    queue<int> sta;
    for (int a : start[i]) {
      sta.push(a);
      dis[a] = 0;
      vis[a] = true;
    }
    que.push({i, sta});
  }
  while (!que.empty()) {
    queue<int> bfs = que.front().second;
    int indice = que.front().first;
    que.pop();
    int max_distance = dis[bfs.front()] + step[indice];
    bool flag = false;
    while (!bfs.empty()) {
      int cur = bfs.front();
      bfs.pop();
      tick[cur] = indice;
      for (int node : adj[cur]) {
        if (arr[node] == '.' && !vis[node]) {
          dis[node] = dis[cur] + 1;
          if (dis[node] > max_distance) {
            bfs.push(cur);
            que.push({indice, bfs});
            flag = true;
            break;
          }
          bfs.push(node);
          vis[node] = true;
        }
      }
      if (flag) break;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (tick[i * m + j] != -1) cnt[tick[i * m + j]]++;
    }
  }
  for (int i = 0; i < p; i++) cout << cnt[i] << ' ';
  return 0;
}
