#include <bits/stdc++.h>
using namespace std;
int n, m, p;
char board[1003][1003];
int t[1003][1003];
int speed[10];
int odw[1003][1003];
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= p; ++i) scanf("%d", &speed[i]);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", board[i]);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (board[i][j] == '.')
        t[i][j + 1] = 0;
      else if (board[i][j] == '#')
        t[i][j + 1] = -1;
      else
        t[i][j + 1] = board[i][j] - (int)'0';
    }
  }
  queue<pair<pair<int, int>, pair<int, int>>> q;
  for (int k = 1; k <= p; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (t[i][j] == k) q.push({{i, j}, {k, 0}});
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    t[i][0] = -1;
    t[i][m + 1] = -1;
  }
  for (int i = 1; i <= m; ++i) {
    t[0][i] = -1;
    t[n + 1][i] = -1;
  }
  queue<pair<pair<int, int>, pair<int, int>>> q2;
  while (!q.empty()) {
    auto w = q.front();
    q.pop();
    int x = w.first.first;
    int y = w.first.second;
    int playerId = w.second.first;
    int dist = w.second.second;
    if (t[x + 1][y] == 0) {
      t[x + 1][y] = playerId;
      q2.push({{x + 1, y}, {playerId, speed[playerId] - 1}});
    }
    if (t[x - 1][y] == 0) {
      t[x - 1][y] = playerId;
      q2.push({{x - 1, y}, {playerId, speed[playerId] - 1}});
    }
    if (t[x][y - 1] == 0) {
      t[x][y - 1] = playerId;
      q2.push({{x, y - 1}, {playerId, speed[playerId] - 1}});
    }
    if (t[x][y + 1] == 0) {
      t[x][y + 1] = playerId;
      q2.push({{x, y + 1}, {playerId, speed[playerId] - 1}});
    }
    if (!q.empty() && q.front().second.first == playerId) continue;
    while (!q2.empty()) {
      auto w = q2.front();
      q2.pop();
      int x = w.first.first;
      int y = w.first.second;
      int playerId = w.second.first;
      int dist = w.second.second;
      if (dist == 0) {
        assert(t[x][y] == playerId);
        q.push({{x, y}, {playerId, dist}});
        continue;
      }
      if (t[x + 1][y] == 0) {
        t[x + 1][y] = playerId;
        q2.push({{x + 1, y}, {playerId, dist - 1}});
      }
      if (t[x - 1][y] == 0) {
        t[x - 1][y] = playerId;
        q2.push({{x - 1, y}, {playerId, dist - 1}});
      }
      if (t[x][y - 1] == 0) {
        t[x][y - 1] = playerId;
        q2.push({{x, y - 1}, {playerId, dist - 1}});
      }
      if (t[x][y + 1] == 0) {
        t[x][y + 1] = playerId;
        q2.push({{x, y + 1}, {playerId, dist - 1}});
      }
    }
  }
  for (int k = 1; k <= p; ++k) {
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (t[i][j] == k) ++cnt;
      }
    }
    printf("%d ", cnt);
  }
}
