#include <bits/stdc++.h>
using namespace std;
int n, m, p, d[20], fix[1001][1001], ass[2000];
set<pair<int, int> > st;
vector<pair<int, int> > v[20];
vector<pair<int, int> > ne;
char c[1001][1001];
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) {
    cin >> d[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') {
        fix[i][j] = -1;
      } else if (c[i][j] == '.') {
        st.insert({(int)i, (int)j});
      } else {
        pair<int, int> xxx = make_pair(i, j);
        v[(c[i][j] - '0')].push_back(xxx);
        fix[i][j] = c[i][j] - '0';
      }
    }
  }
  while (true) {
    int kkk = 0;
    for (int i = 1; i <= p; i++) {
      queue<pair<pair<int, int>, int> > q;
      for (int j = 0; j < v[i].size(); j++) {
        q.push({(v[i][j]), 0LL});
      }
      ne.clear();
      while (q.size()) {
        pair<pair<int, int>, int> u = q.front();
        if (u.second + 1 > d[i]) {
          q.pop();
          continue;
        }
        if (u.first.first < n && fix[u.first.first + 1][u.first.second] == 0) {
          fix[u.first.first + 1][u.first.second] = i;
          ne.push_back({u.first.first + 1, u.first.second});
          q.push({{u.first.first + 1, u.first.second}, u.second + 1});
        }
        if (u.first.second < m && fix[u.first.first][u.first.second + 1] == 0) {
          fix[u.first.first][u.first.second + 1] = i;
          ne.push_back({u.first.first, u.first.second + 1});
          q.push({{u.first.first, u.first.second + 1}, u.second + 1});
        }
        if (u.first.first > 1 && fix[u.first.first - 1][u.first.second] == 0) {
          fix[u.first.first - 1][u.first.second] = i;
          ne.push_back({u.first.first - 1, u.first.second});
          q.push({{u.first.first - 1, u.first.second}, u.second + 1});
        }
        if (u.first.second > 1 && fix[u.first.first][u.first.second - 1] == 0) {
          fix[u.first.first][u.first.second - 1] = i;
          ne.push_back({u.first.first, u.first.second - 1});
          q.push({{u.first.first, u.first.second - 1}, u.second + 1});
        }
        q.pop();
      }
      v[i].clear();
      kkk += ne.size();
      for (int j = 0; j < ne.size(); j++) v[i].push_back(ne[j]);
    }
    if (!kkk) break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (fix[i][j] != -1) ass[fix[i][j]]++;
    }
  }
  for (int i = 1; i <= p; i++) cout << ass[i] << " ";
  return 0;
}
