#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int mv[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int n, m, p;
long long s[maxn];
bool mp[maxn][maxn];
int ans[maxn];
struct node {
  int x, y;
  long long num;
  int color;
  int ft;
  node() {}
  node(int _x, int _y, int _color) {
    x = _x;
    y = _y;
    color = _color;
  }
  void insert(int _x, int _y, int _color, long long _num, int _o) {
    x = _x;
    y = _y;
    ft = _o;
    num = _num - 1;
    color = _color;
    if (_num == 1) {
      num = s[_color];
      ++ft;
    }
  }
  bool friend operator<(const node &a, const node &b) {
    if (a.ft == b.ft) {
      if (a.color == b.color) {
        if (a.num == b.num)
          return a.x > b.x;
        else
          return a.num < b.num;
      } else {
        return a.color > b.color;
      }
    } else {
      return a.ft > b.ft;
    }
  }
};
vector<node> ve;
void solve() {
  priority_queue<node> sk;
  for (auto s : ve) sk.push(s);
  while (!sk.empty()) {
    node top = sk.top();
    sk.pop();
    for (int i = 0; i < 4; i++) {
      int x = top.x + mv[i][0];
      int y = top.y + mv[i][1];
      if (x >= n || y >= m || x < 0 || y < 0 || mp[x][y]) continue;
      mp[x][y] = true;
      ++ans[top.color];
      node f;
      f.insert(x, y, top.color, top.num, top.ft);
      sk.push(f);
    }
  }
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  cout << endl;
}
int main() {
  while (~scanf("%d%d%d", &n, &m, &p)) {
    memset(ans, 0, sizeof(ans));
    ve.clear();
    for (int i = 1; i <= p; i++) scanf("%lld", s + i);
    getchar();
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int c = getchar();
        if (c == '.')
          mp[i][j] = false;
        else {
          mp[i][j] = true;
          if (c == '#') continue;
          ans[c - '0']++;
          node f = node(i, j, c - '0');
          f.ft = 0;
          f.num = s[c - '0'];
          ve.push_back(f);
        }
      }
      getchar();
    }
    solve();
  }
  return 0;
}
