#include <bits/stdc++.h>
using namespace std;
int n, m;
char buf[31];
int a[31][31];
int b[29], c[29];
bool used[7][7];
int d[15];
int cnt;
int ans;
char res[31][31];
void dfs(int x) {
  if (x > 6) {
    for (int i = 0; i <= 6; i++) {
      for (int j = 0; j <= 6; j++) used[i][j] = false;
    }
    for (int i = 1; i <= 28; i++) {
      if (used[d[b[i]]][d[c[i]]]) return;
      used[d[b[i]]][d[c[i]]] = used[d[c[i]]][d[b[i]]] = true;
    }
    if (!ans) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          if (!a[i][j])
            res[i][j] = '.';
          else
            res[i][j] = '0' + d[a[i][j]];
        }
      }
    }
    ans++;
    return;
  }
  for (int i = 1; i <= 14; i++) {
    if (d[i] != -1) continue;
    d[i] = x;
    for (int j = i + 1; j <= 14; j++) {
      if (d[j] != -1) continue;
      d[j] = x;
      dfs(x + 1);
      d[j] = -1;
    }
    d[i] = -1;
    break;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", buf + 1);
    for (int j = 1; j <= m; j++) {
      if (buf[j] == '.') continue;
      if (!a[i][j])
        a[i][j] = a[i][j + 1] = a[i + 1][j] = a[i + 1][j + 1] = ++cnt;
      int v;
      if (buf[j] <= 'B')
        v = buf[j] - 'A' + 1;
      else
        v = buf[j] - 'a' + 3;
      if (!b[v])
        b[v] = a[i][j];
      else
        c[v] = a[i][j];
    }
  }
  for (int i = 1; i <= 14; i++) d[i] = -1;
  dfs(0);
  printf("%lld\n", 5040LL * ans);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%c", res[i][j]);
    puts("");
  }
  return 0;
}
