#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << '(' << p.first << ',' << p.second << ')';
  return out;
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<vector<T>>& v) {
  for (auto& x : v) out << x << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
long long gcd(long long a, long long b) {
  if (b > a) swap(a, b);
  return (b ? gcd(b, a % b) : a);
}
const long double pi = 2 * asin(1);
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.setstate(ios::failbit);
  vector<pair<int, int>> dir = {make_pair(0, -1), make_pair(0, 1),
                                make_pair(1, 0), make_pair(-1, 0)};
  int n, m, p, x, y;
  cin >> n >> m >> p;
  vector<int> s(p);
  cin >> s;
  vector<string> g(n);
  cin >> g;
  vector<queue<pair<pair<int, int>, int>>> q(p);
  pair<pair<int, int>, int> P;
  queue<pair<pair<int, int>, int>> Q;
  for (register int k = 0; k < p; k++) {
    for (register int i = 0; i < n; i++)
      for (register int j = 0; j < m; j++) {
        if (g[i][j] == '1' + k) {
          q[k].push(make_pair(make_pair(i, j), s[k]));
        }
      }
  }
  for (register int _ = 0; _ < n * m + 2; _++) {
    for (register int k = 0; k < p; k++) {
      Q = q[k];
      while (!q[k].empty()) q[k].pop();
      while (!Q.empty()) {
        P = Q.front();
        Q.pop();
        for (auto z : dir) {
          x = P.first.first + z.first;
          y = P.first.second + z.second;
          if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '.') {
            g[x][y] = '1' + k;
            if (P.second == 1) q[k].push(make_pair(make_pair(x, y), s[k]));
            if (P.second != 1) Q.push(make_pair(make_pair(x, y), P.second - 1));
          }
        }
      }
    }
  }
  vector<int> ans(p);
  for (register int i = 0; i < n; i++)
    for (register int j = 0; j < m; j++) {
      if (isdigit(g[i][j])) ans[g[i][j] - '1']++;
    }
  cout << ans;
}
