#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long i, j, k, l, n, m, p, q, r, d, su, sx, sy,
    prod = 1, maxi, a, b, c, w, x, y, o, e, f, mini = 1000000000, t, cnt;
string s, s1, s2;
long long ar[10], br[10], cr[10], ans[10], last_ans[10];
char ch[1003][1003];
int vis[1003][1003];
queue<pair<long long, long long>> qu[10];
long long modularExponentiation(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % 1000000007, n / 2);
  else
    return (x * modularExponentiation((x * x) % 1000000007, (n - 1) / 2)) %
           1000000007;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first > b.first);
}
long long modInverse(long long n) {
  return modularExponentiation(n, 998244353 - 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    cin >> n >> m >> a;
    for (long long i = 1; i < a + 1; i++) cin >> ar[i];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) cin >> ch[i][j];
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (ch[i][j] - '0' < 10 && ch[i][j] - '0' > 0) {
          ans[ch[i][j] - '0']++;
          qu[ch[i][j] - '0'].push(make_pair(i, j));
          vis[i][j] = 1;
        }
        if (ch[i][j] == '#') vis[i][j] = 1;
      }
    }
    while (!b) {
      for (long long i = 1; i < a + 1; i++) {
        queue<pair<long long, pair<long long, long long>>> new_qu;
        while (!qu[i].empty()) {
          auto q = qu[i].front();
          qu[i].pop();
          new_qu.push(make_pair(ar[i], q));
        }
        while (!new_qu.empty()) {
          auto p = new_qu.front();
          new_qu.pop();
          long long dist = p.first;
          x = p.second.first, y = p.second.second;
          if (dist == 0) {
            continue;
          }
          if (x + 1 < n && vis[x + 1][y] == 0) {
            ans[i]++;
            new_qu.push(make_pair(dist - 1, make_pair(x + 1, y)));
            vis[x + 1][y] = 1;
            if (dist == 1) {
              qu[i].push(make_pair(x + 1, y));
            }
          }
          if (y + 1 < m && vis[x][y + 1] == 0) {
            ans[i]++;
            new_qu.push(make_pair(dist - 1, make_pair(x, y + 1)));
            vis[x][y + 1] = 1;
            if (dist == 1) {
              qu[i].push(make_pair(x, y + 1));
            }
          }
          if (x - 1 >= 0 && vis[x - 1][y] == 0) {
            ans[i]++;
            new_qu.push(make_pair(dist - 1, make_pair(x - 1, y)));
            vis[x - 1][y] = 1;
            if (dist == 1) {
              qu[i].push(make_pair(x - 1, y));
            }
          }
          if (y - 1 >= 0 && vis[x][y - 1] == 0) {
            ans[i]++;
            new_qu.push(make_pair(dist - 1, make_pair(x, y - 1)));
            vis[x][y - 1] = 1;
            if (dist == 1) {
              qu[i].push(make_pair(x, y - 1));
            }
          }
        }
      }
      b = 1;
      for (long long i = 1; i < a + 1; i++)
        if (last_ans[i] != ans[i]) {
          b = 0;
          break;
        }
      for (long long i = 1; i < a + 1; i++) last_ans[i] = ans[i];
    }
    for (long long i = 1; i < a + 1; i++) cout << ans[i] << " ";
  }
  return 0;
}
