#include <bits/stdc++.h>
inline int sbt(int x) { return __builtin_popcount(x); }
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
char a[1013][1013];
bool vis[1013][1013];
int res[13];
int dx[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n, m, p;
  cin >> n >> m >> p;
  int s[13];
  for (int i = 1; i <= p; i++) {
    cin >> s[i];
  }
  queue<pair<int, pair<int, int>>> q[13];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] != '#' && a[i][j] != '.') {
        q[a[i][j] - '0'].push(make_pair(a[i][j] - '0', make_pair(i, j)));
      }
    }
  }
  int curr = 1;
  int ok = 1;
  while (ok) {
    ok = 0;
    for (int i = 1; i <= p; i++) {
      int steps = s[i];
      int kuch_ho_rha_hai = 1;
      while (steps && kuch_ho_rha_hai) {
        steps--;
        kuch_ho_rha_hai = 0;
        queue<pair<int, pair<int, int>>> tmp;
        while (!q[i].empty()) {
          tmp.push(q[i].front());
          q[i].pop();
        }
        while (!tmp.empty()) {
          auto p = tmp.front();
          tmp.pop();
          for (int ii = 0; ii <= 3; ii++) {
            int dxx = dx[ii][0] + p.second.first;
            int dyy = dx[ii][1] + p.second.second;
            int steps = s[i];
            if (dxx >= 1 && dyy >= 1 && dxx <= n && dyy <= m &&
                a[dxx][dyy] == '.') {
              a[dxx][dyy] = char(i + 48);
              q[i].push(make_pair(i, make_pair(dxx, dyy)));
              kuch_ho_rha_hai++;
              ok++;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != '#' && a[i][j] != '.') res[a[i][j] - '0']++;
    }
  }
  for (int i = 1; i <= p; i++) {
    cout << res[i] << ' ';
  }
  return 0;
}
