#include <bits/stdc++.h>
using namespace std;
char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
inline long long readll() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
inline void write(int x) {
  if (!x) putchar('0');
  if (x < 0) x = -x, putchar('-');
  static int sta[20];
  register int tot = 0;
  while (x) sta[tot++] = x % 10, x /= 10;
  while (tot) putchar(sta[--tot] + 48);
}
const int maxn = 200007, INF = 0x3f3f3f3f;
const int MOD = 998244353;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long long P = 19260817;
inline int mod1(int x) { return x < MOD ? x : x - MOD; }
inline int mod2(int x) { return x < 0 ? x + MOD : x; }
inline void add(int &x, int y) { x = mod1(x + y); }
inline void sub(int &x, int y) { x = mod2(x - y); }
int n, m;
int c[57][57], v[57], f[57][57], ans, tot, flag;
char s[maxn], b[57][57];
vector<int> a[maxn];
bool check() {
  memset(f, 0, sizeof(f));
  for (int i = 0, x, y; i < 28; i++) {
    if (f[x = v[a[i][0]]][y = v[a[i][1]]]) return 0;
    f[x][y] = f[y][x] = 1;
  }
  return 1;
}
void dfs(int x, int y) {
  if (x == 15) {
    if (check()) {
      ans++;
      if (!flag) {
        flag = 1;
        for (int i = 1; i <= n; i++) {
          for (int j = 1; j <= m; j++) {
            if (!c[i][j])
              b[i][j] = '.';
            else
              b[i][j] = v[c[i][j]] + '0';
          }
        }
      }
    }
  }
  if (v[x] != -1) {
    dfs(x + 1, y);
    return;
  }
  v[x] = y;
  for (int i = 1; i <= 14; i++) {
    if (v[i] == -1) {
      v[i] = y;
      dfs(x + 1, y + 1);
      v[i] = -1;
    }
  }
  v[x] = -1;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(v, -1, sizeof(v));
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      if (s[j] != '.') {
        if (!c[i][j])
          c[i][j] = c[i + 1][j] = c[i][j + 1] = c[i + 1][j + 1] = ++tot;
        a[s[j] >= 'a' ? s[j] - 'a' : s[j] - 'A' + 26].push_back(c[i][j]);
      }
    }
  }
  dfs(1, 0);
  printf("%d\n", ans * 5040);
  for (int i = 1; i <= n; i++) puts(b[i] + 1);
  return 0;
}
