#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t, n, m, x, y, c, k, p, newx, newy, xx, yy, mov;
int f[N], a[N], b[N], sp[4];
char s[1004][1004];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool vis[1003][1003];
bool valid(int i, int j) {
  return (i >= 0 && i < n && j >= 0 && j < m && s[i][j] == '.');
}
vector<queue<pair<int, int>>> q(10);
pair<int, int> pt;
void bfs(int pl) {
  while (t < p) {
    mov = a[pl];
    while (!q[pl].empty() && mov) {
      k = q[pl].size();
      bool bb = 0;
      for (int j = 0; j < (int)k; ++j) {
        pt = q[pl].front();
        q[pl].pop();
        for (int i = 0; i < (int)4; ++i) {
          newx = pt.first + dx[i];
          newy = pt.second + dy[i];
          if (valid(newx, newy)) {
            bb = 1;
            q[pl].push({newx, newy});
            if (vis[newx][newy] == 0) ++f[pl], s[newx][newy] = pl + '0';
          }
        }
      }
      if (bb) --mov;
    }
    if (q[pl].empty() && !b[pl]) ++t, b[pl] = 1;
    ++pl;
    if (pl > p) pl = 1;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= (int)p; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < (int)n; ++i) scanf("%s", s[i]);
  for (int i = 0; i < (int)n; ++i)
    for (int j = 0; j < (int)m; ++j)
      if (s[i][j] != '.' && s[i][j] != '#')
        q[s[i][j] - '0'].push({i, j}), ++f[s[i][j] - '0'];
  bfs(1);
  for (int i = 1; i <= (int)p; ++i) printf("%d ", f[i]);
  return 0;
}
