#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 1e3 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;
int mv[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int rmv[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
int ok[MAXN][MAXN][4], OK[MAXN][MAXN], grid[MAXN][MAXN], s[MAXN];
set<pair<int, int>> av[11];
vector<int> G[MAXN], castles[10];
vector<ll> V;
set<ll> S;
map<ll, int> M;
stack<ll> St;
queue<ll> Q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << setprecision(13) << fixed;
  int n, m, p;
  cin >> n >> m >> p;
  for (int i = 1; i <= p; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c != '.') {
        if (c == '#') {
          grid[i][j] = 10;
        } else {
          grid[i][j] = c - '0';
        }
      }
    }
  }
  for (int i = 0; i <= max(n, m) + 1; i++) {
    grid[0][i] = grid[i][0] = grid[n + 1][i] = grid[i][m + 1] = 10;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 0; k < 4; k++) {
        if (not grid[i + mv[k][0]][j + mv[k][1]]) {
          ok[i][j][k] = 1;
          OK[i][j] = 1;
        }
      }
      if (grid[i][j] and OK[i][j]) {
        av[grid[i][j]].insert({i, j});
      }
    }
  }
  while (true) {
    for (int t = 1; t <= p; t++) {
      queue<pair<pair<int, int>, int>> Q;
      for (auto &i : av[t]) {
        Q.push({i, 0});
      }
      while (!Q.empty()) {
        auto pole = Q.front().first;
        int w = Q.front().second;
        Q.pop();
        av[t].erase(pole);
        int i = pole.first, j = pole.second;
        for (int k = 0; k < 4; k++) {
          int x = i + mv[k][0], y = j + mv[k][1];
          if (not grid[x][y]) {
            grid[x][y] = t;
            if (w + 1 < s[t]) {
              Q.push({{x, y}, w + 1});
            }
            av[t].insert({x, y});
          }
        }
      }
    }
    bool Ok = 0;
    for (int t = 1; t <= p; t++) {
      if (not av[t].empty()) {
        Ok = 1;
        break;
      }
    }
    if (not Ok) {
      break;
    }
  }
  for (int t = 1; t <= p; t++) {
    int ctr = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        ctr += (grid[i][j] == t);
      }
    }
    cout << ctr << " ";
  }
  cout << "\n";
}
