#include <bits/stdc++.h>
using namespace std;
int _pow(int a, int b, int mo) {
  int tmp = 1;
  a %= mo;
  for (; b; b >>= 1) {
    if (b & 1) tmp = (long long)tmp * a % mo;
    a = (long long)a * a % mo;
  }
  return tmp;
}
template <class T>
inline void R(T &xx) {
  xx = 0;
  char ch = getchar();
  bool F = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') F = 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
  if (F) xx = -xx;
}
int c[33][33], v[33], n, m, t, ans;
char s[33], b[33][33];
vector<int> a[33];
bool f[33][33];
inline bool che() {
  memset(f, 0, sizeof(f));
  int x, y;
  for (int i = 0; i < (int)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 (che()) {
      if (!(ans++))
        for (int i = 1; i <= n; i++)
          for (int j = 1; j <= m; j++)
            b[i][j] = c[i][j] ? v[c[i][j]] + '0' : '.';
    }
    return;
  }
  if (~v[x])
    dfs(x + 1, y);
  else {
    v[x] = y;
    for (int i = 1; i <= 14; i++)
      if (!(~v[i])) v[i] = y, dfs(x + 1, y + 1), v[i] = -1;
    v[x] = -1;
  }
}
int main() {
  R(n), R(m);
  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] = ++t;
        a[s[j] >= 'a' ? s[j] - 'a' : s[j] - 'A' + 26].push_back(c[i][j]);
      }
  }
  memset(v, -1, sizeof(v));
  dfs(1, 0);
  printf("%I64d\n", 5040ll * ans);
  for (int i = 1; i <= n; i++) puts(b[i] + 1);
  return 0;
}
