#include <bits/stdc++.h>
using namespace std;
int n, m, p;
const int N = 1000 + 9;
char arr[N][N];
int toint(char x) { return x - '0'; }
bool vis[N][N];
bool val(int x, int y) {
  return (x < n && x > -1 && y < m && y > -1 && !vis[x][y] && arr[x][y] == '.');
}
int ans[N];
int main() {
  scanf("%d%d%d", &n, &m, &p);
  vector<vector<pair<int, int>>> adj(p + 1);
  int speed[p + 1];
  for (int i = 1; i <= p; i++) scanf("%d", speed + i);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; ++j) {
      scanf(" %c", &arr[i][j]);
      if (arr[i][j] != '.' && arr[i][j] != '#') {
        adj[toint(arr[i][j])].push_back({i, j});
        ans[toint(arr[i][j])]++;
      }
    }
  }
  int xd[] = {0, 1, 0, -1};
  int yd[] = {1, 0, -1, 0};
  bool is = 1;
  while (is) {
    is = 0;
    for (int i = 1; i <= p; i++) {
      if (!adj[i].empty()) is = 1;
      queue<pair<pair<int, int>, int>> q;
      for (auto j : adj[i]) {
        q.push({j, 0});
      }
      adj[i].clear();
      while (!q.empty()) {
        int x = q.front().first.first;
        int y = q.front().first.second;
        int level = q.front().second;
        q.pop();
        if (level == speed[i]) {
          adj[i].push_back({x, y});
          continue;
        }
        for (int j = 0; j < 4; j++) {
          int xx = x + xd[j];
          int yy = y + yd[j];
          if (val(xx, yy)) {
            vis[xx][yy] = 1;
            ans[i]++;
            q.push({{xx, yy}, level + 1});
          }
        }
      }
    }
  }
  for (int i = 1; i <= p; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
