#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[1008][1008], last[1008][1008];
int a[58][58];
int flag[58], x[58], y[58];
int ans, tot;
bool in[8][8];
struct Tprogram {
  void open() {
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
  }
  void close() {}
  void init() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%s", &s[i][1]);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        if (s[i][j] != '.' && !a[i][j])
          a[i][j] = a[i + 1][j] = a[i][j + 1] = a[i + 1][j + 1] = ++tot;
        if (s[i][j] != '.') {
          int t = s[i][j];
          t = t <= 'B' ? t - 64 : t - 94;
          if (!x[t])
            x[t] = a[i][j];
          else
            y[t] = a[i][j];
        }
      }
  }
  void dfs(int c, int d) {
    if (d > 14) {
      memset(in, 0, sizeof(in));
      for (int i = 1; i <= 28; i++)
        if (!in[flag[x[i]]][flag[y[i]]])
          in[flag[x[i]]][flag[y[i]]] = in[flag[y[i]]][flag[x[i]]] = 1;
        else
          return;
      ++ans;
      if (ans == 1) {
        for (int i = 1; i <= n; i++)
          for (int j = 1; j <= m; j++) {
            if (a[i][j])
              last[i][j] = flag[a[i][j]] - 1 + '0';
            else
              last[i][j] = '.';
          }
      }
      return;
    }
    if (flag[d])
      dfs(c, d + 1);
    else {
      flag[d] = c;
      for (int i = d + 1; i <= 14; i++)
        if (!flag[i]) {
          flag[i] = c;
          dfs(c + 1, d + 1);
          flag[i] = 0;
        }
      flag[d] = 0;
    }
  }
  void work() {
    dfs(1, 1);
    printf("%d\n", ans * 5040);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) printf("%c", last[i][j]);
      printf("\n");
    }
  }
} Program;
int main() {
  Program.init();
  Program.work();
  return 0;
}
