#include <bits/stdc++.h>
struct State {
  int row, col;
  int dist;
};
int grid[1000][1000];
long speeds[9];
int N, M, P;
std::vector<std::queue<State>> qs;
std::vector<int> counts;
long tot;
int main() {
  std::scanf("%d %d %d", &N, &M, &P);
  qs.resize(P);
  counts.resize(P, 0);
  tot = N * M;
  for (int i = 0; i < P; ++i) {
    std::scanf("%ld", &speeds[i]);
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      char c;
      std::cin >> c;
      if (c == '.') {
        grid[i][j] = 0;
      } else if (c == '#') {
        grid[i][j] = -1;
        --tot;
      } else {
        int p = c - '0';
        qs[p - 1].push({i, j, 0});
        grid[i][j] = p;
        --tot;
        ++counts[p - 1];
      }
    }
  }
  for (int step = 1; tot > 0; ++step) {
    bool can_continue = false;
    for (int i = 0; i < P; ++i) {
      int maxDist = step * speeds[i];
      while (!qs[i].empty() && qs[i].front().dist < maxDist) {
        can_continue = true;
        State curr = qs[i].front();
        qs[i].pop();
        if (curr.row > 0 && grid[curr.row - 1][curr.col] == 0) {
          grid[curr.row - 1][curr.col] = i + 1;
          qs[i].push({curr.row - 1, curr.col, curr.dist + 1});
          ++counts[i];
          --tot;
        }
        if (curr.row < N - 1 && grid[curr.row + 1][curr.col] == 0) {
          grid[curr.row + 1][curr.col] = i + 1;
          qs[i].push({curr.row + 1, curr.col, curr.dist + 1});
          ++counts[i];
          --tot;
        }
        if (curr.col > 0 && grid[curr.row][curr.col - 1] == 0) {
          grid[curr.row][curr.col - 1] = i + 1;
          qs[i].push({curr.row, curr.col - 1, curr.dist + 1});
          ++counts[i];
          --tot;
        }
        if (curr.col < M - 1 && grid[curr.row][curr.col + 1] == 0) {
          grid[curr.row][curr.col + 1] = i + 1;
          qs[i].push({curr.row, curr.col + 1, curr.dist + 1});
          ++counts[i];
          --tot;
        }
      }
    }
    if (!can_continue) {
      break;
    }
  }
  std::printf("%d", counts[0]);
  for (int i = 1; i < P; ++i) {
    std::printf(" %d", counts[i]);
  }
  std::printf("\n");
  return 0;
}
