#include <bits/stdc++.h>
using namespace std;
const int P = 9;
const int N = 1000;
int n, m, p;
pair<int, int> v[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool inside(int x, int y) { return (x < n && x >= 0 && y < m && y >= 0); }
bool found = true;
int sol[P + 1], s[P + 1], board[N][N], d[N][N];
queue<pair<int, int> > q[P + 1];
void bfs(int player, int limit) {
  int x, y, xx, yy;
  while (!q[player].empty()) {
    x = q[player].front().first;
    y = q[player].front().second;
    if (d[x][y] == limit) break;
    q[player].pop();
    for (auto p : v) {
      xx = x + p.first;
      yy = y + p.second;
      if (inside(xx, yy) && board[xx][yy] == 0) {
        found = true;
        board[xx][yy] = player;
        d[xx][yy] = 1 + d[x][y];
        q[player].push({xx, yy});
      }
    }
  }
}
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c - '0' <= p && 0 < c - '0') {
        q[c - '0'].push({i, j});
        board[i][j] = c - '0';
      } else if (c == '#')
        board[i][j] = -1;
    }
  int cnt = 1;
  while (found) {
    found = false;
    for (int i = 1; i <= p; i++)
      if (!q[i].empty()) bfs(i, cnt * s[i]);
    cnt++;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (board[i][j] != -1) sol[board[i][j]]++;
  for (int i = 1; i <= p; i++) cout << sol[i] << ' ';
  return 0;
}
