#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int w, h, bum, wum, sum, B, W;
char s[60][60];
void func1(int y, int x) {
  int p = y, q = x;
  if (s[y][x] == 'B') {
    B++;
  } else if (s[y][x] == 'W') {
    W++;
  } else if (s[y][x] != '*') {
    s[y][x] = '*';
    sum++;
    for (int l = 0; l < 4; l++) {
      y = p + dy[l];
      x = q + dx[l];
      if (y >= 0 && y < h && x >= 0 && x < w) {
        func1(y, x);
      }
    }
  }
}
void func2(int y, int x, char c) {
  int p, q;
  if (s[y][x] == '*') {
    s[y][x] = c;
    for (int o = 0; o < 4; o++) {
      p = y + dy[o];
      q = x + dx[o];
      if (p >= 0 && p < h && q >= 0 && q < w) func2(p, q, c);
    }
  }
}
int main() {
  while (cin >> w >> h, w || h) {
    wum = 0;
    bum = 0;
    for (int i = 0; i < h; i++) scanf("%s", s[i]);
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) {
        if (s[i][j] == '.') {
          B = 0;
          W = 0;
          sum = 0;
          func1(i, j);
          if (B > 0 && W == 0) {
            bum += sum;
            func2(i, j, 's');
          } else if (B == 0 && W > 0) {
            wum += sum;
            func2(i, j, 't');
          } else {
            func2(i, j, 'D');
          }
        }
      }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) cout << s[i][j];
      cout << endl;
    }
    cout << bum << ' ' << wum << endl;
  }
  return 0;
}
