#include <bits/stdc++.h>
using namespace std;
int arr[1001][1001], num[1001][1001], s[10], ans[10];
queue<pair<int, int> > qu[10];
int main() {
  int n, m, p;
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &p);
  for (int i = 1; i <= p; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= n; i++) {
    string str;
    cin >> str;
    int len = str.length();
    for (int j = 0; j < len; j++) {
      if (str[j] == '.')
        num[i][j + 1] = 0;
      else if (str[j] == '#')
        num[i][j + 1] = -1;
      else {
        num[i][j + 1] = str[j] - '0';
        qu[num[i][j + 1]].push(make_pair(i, j + 1));
      }
    }
  }
  bool flag = 1;
  while (flag) {
    flag = 0;
    for (int i = 1; i <= p; i++) {
      for (int j = 1; j <= s[i]; j++) {
        int len = qu[i].size();
        while (!qu[i].empty() && len > 0) {
          len--;
          int x = qu[i].front().first, y = qu[i].front().second;
          qu[i].pop();
          if (x - 1 > 0 && num[x - 1][y] == 0) {
            num[x - 1][y] = i;
            qu[i].push(make_pair(x - 1, y));
            flag = 1;
          }
          if (x + 1 <= n && num[x + 1][y] == 0) {
            num[x + 1][y] = i;
            qu[i].push(make_pair(x + 1, y));
            flag = 1;
          }
          if (y - 1 > 0 && num[x][y - 1] == 0) {
            num[x][y - 1] = i;
            qu[i].push(make_pair(x, y - 1));
            flag = 1;
          }
          if (y + 1 <= m && num[x][y + 1] == 0) {
            num[x][y + 1] = i;
            qu[i].push(make_pair(x, y + 1));
            flag = 1;
          }
        }
        if (qu[i].empty()) break;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (num[i][j] != -1) ans[num[i][j]]++;
  for (int i = 1; i <= p; i++) cout << ans[i] << " ";
  cout << endl;
}
