#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, p;
  cin >> n >> m >> p;
  vector<int> s(p + 1);
  for (int i = 1; i <= p; ++i) {
    cin >> s[i];
  }
  struct Pos {
    int x, y;
  };
  vector<queue<Pos>> q(p + 1);
  vector<vector<char>> g(n + 2, vector<char>(m + 2, '#'));
  vector<int> resp(p + 1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> g[i][j];
      if (g[i][j] > '0' && g[i][j] <= '9') {
        q[g[i][j] - '0'].push({i, j});
        resp[g[i][j] - '0']++;
      }
    }
  }
  int roff[]{0, 1, 0, -1};
  int coff[]{-1, 0, 1, 0};
  bool hasTurn = true;
  int time = 0;
  while (hasTurn) {
    hasTurn = false;
    for (int i = 1; i <= p; ++i) {
      int j = s[i];
      while (j-- && !q[i].empty()) {
        int sz = q[i].size();
        while (sz-- > 0) {
          auto u = q[i].front();
          q[i].pop();
          for (int k = 0; k < 4; ++k) {
            int r = u.x + roff[k];
            int c = u.y + coff[k];
            if (g[r][c] == '.') {
              g[r][c] = '0' + i;
              resp[i]++;
              hasTurn = true;
              q[i].push({r, c});
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= p; ++i) cout << resp[i] << " ";
  return 0;
}
