#include <bits/stdc++.h>
using namespace std;
const int N = 35, cnt = 14;
int v[N], f[N][N], a1[N], a[N][2], n, m, s = 0, ans;
char ans1[N][N], c[N][N];
bool can() {
  int x, y;
  memset(f, 0, sizeof(f));
  for (int i = 0; i < cnt + cnt; ++i)
    if (f[x = v[a[i][0]]][y = v[a[i][1]]])
      return 0;
    else
      f[x][y] = f[y][x] = 1;
  return 1;
}
void dfs(int x, int y) {
  if (x > cnt) {
    if (can()) {
      ++ans;
      for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
          ans1[i][j] = c[i][j] ? v[c[i][j]] + '0' : '.';
    }
    return;
  }
  if (v[x] != -1)
    dfs(x + 1, y);
  else {
    v[x] = y;
    for (int i = x + 1; i <= cnt; ++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);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      char ch;
      scanf(" %c", &ch);
      if (ch == '.') continue;
      if (!c[i][j]) c[i][j] = c[i + 1][j] = c[i][j + 1] = c[i + 1][j + 1] = ++s;
      int id = ch >= 'a' ? ch - 'a' : ch - 'A' + 26;
      a[id][a1[id]++] = c[i][j];
    }
  memset(v, -1, sizeof(v));
  dfs(1, 0);
  printf("%d\n", ans * 5040);
  for (int i = 1; i <= n; ++i) puts(ans1[i] + 1);
  return 0;
}
