#include <bits/stdc++.h>
using namespace std;
long long fn(long long x, long long rn[]) {
  if (x == rn[x])
    return x;
  else
    return rn[x] = fn(rn[x], rn);
}
bool un(long long x, long long y, long long rn[], long long sz[]) {
  x = fn(x, rn);
  y = fn(y, rn);
  if (x == y) return false;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  rn[y] = x;
  return true;
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long MOD = 9982453;
long long mod = 1000000007;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long inv(long long val, long long MODx = MOD) {
  return power(val, MODx - 2, MODx);
}
vector<long long> fac, ifac;
void preFac(long long sz) {
  fac.resize(sz + 1), ifac.resize(sz + 1);
  fac[0] = 1;
  for (int i = 1; i <= sz; i++) {
    fac[i] = (i * fac[i - 1]) % MOD;
  }
  ifac[sz] = inv(fac[sz]);
  for (int i = sz - 1; i >= 0; i--) {
    ifac[i] = ((i + 1) * ifac[i + 1]) % MOD;
  }
}
long long nCr(long long N, long long R) {
  if (R <= N and R >= 0) {
    return ((fac[N] * ifac[R]) % MOD * ifac[N - R]) % MOD;
  }
  return 0;
}
static vector<vector<vector<pair<long long, long long>>>> v(
    1001, vector<vector<pair<long long, long long>>>(1001));
static vector<long long> ans(10, 0);
static queue<pair<long long, long long>> q[10];
static vector<vector<long long>> vis(1001, vector<long long>(1001, 0));
static vector<long long> speed(10);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, p;
  cin >> n >> m >> p;
  for (long long i = 1; i <= p; i++) {
    cin >> speed[i];
  }
  string s[n];
  for (long long i = 0; i <= n - 1; i++) {
    cin >> s[i];
  }
  for (long long i = 0; i <= n - 1; i++) {
    for (long long j = 0; j <= m - 1; j++) {
      if (s[i][j] != '#' and s[i][j] != '.') {
        q[s[i][j] - '0'].push({i, j});
        vis[i][j] = 1;
      }
    }
  }
  for (long long i = 0; i <= n - 1; i++) {
    for (long long j = 0; j <= m - 1; j++) {
      if (s[i][j] != '#') {
        if (i + 1 < n and s[i + 1][j] != '#') {
          v[i][j].push_back({i + 1, j});
        }
        if (i - 1 >= 0 and s[i - 1][j] != '#') {
          v[i][j].push_back({i - 1, j});
        }
        if (j + 1 < m and s[i][j + 1] != '#') {
          v[i][j].push_back({i, j + 1});
        }
        if (j - 1 >= 0 and s[i][j - 1] != '#') {
          v[i][j].push_back({i, j - 1});
        }
      }
    }
  }
  while (1) {
    long long flg = 0;
    for (long long x = 1; x <= p; x++) {
      map<pair<long long, long long>, long long> dis;
      vector<pair<long long, long long>> endp;
      while (!q[x].empty()) {
        flg = 1;
        pair<long long, long long> pp = q[x].front();
        q[x].pop();
        if (dis[pp] == speed[x]) {
          endp.push_back(pp);
          continue;
        }
        ans[x]++;
        for (auto u : v[pp.first][pp.second]) {
          if (vis[u.first][u.second]) {
            continue;
          }
          dis[u] = dis[pp] + 1;
          if (dis[u] <= speed[x]) {
            vis[u.first][u.second] = 1;
          }
          q[x].push(u);
        }
      }
      for (auto u : endp) {
        q[x].push(u);
      }
    }
    if (flg == 0) {
      break;
    }
  }
  for (long long i = 1; i <= p; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
