#include <bits/stdc++.h>
using namespace std;
const int maxn = 55, maxm = 9;
int loc[maxn][2], col[maxn];
char s[maxn][maxn], res[maxn][maxn];
int num[maxn][maxn], used[maxm][maxm];
int n, m, ans, cnt;
void dfs(int u, int v) {
  int i, j, x, y;
  if (u > 14) {
    memset(used, 0, sizeof used);
    for (i = 1; i <= 28; ++i) {
      x = col[loc[i][0]];
      y = col[loc[i][1]];
      if (used[x][y]) return;
      used[x][y] = used[y][x] = true;
    }
    ++ans;
    if (ans == 1) {
      for (i = 1; i <= n; ++i)
        for (j = 1, res[i][m + 1] = '\0'; j <= m; ++j)
          res[i][j] = num[i][j] ? col[num[i][j]] - 1 + '0' : '.';
    }
    return;
  }
  if (col[u])
    dfs(u + 1, v);
  else {
    for (i = u + 1, col[u] = v; i <= 14; ++i)
      if (!col[i]) {
        col[i] = v;
        dfs(u + 1, v + 1);
        col[i] = 0;
      }
    col[u] = 0;
  }
}
int main() {
  int i, j, t;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j)
      if (s[i][j] != '.') {
        if (!num[i][j])
          num[i][j] = num[i + 1][j] = num[i][j + 1] = num[i + 1][j + 1] = ++cnt;
        t = s[i][j] < 'a' ? s[i][j] - 'A' + 27 : s[i][j] - 'a' + 1;
        if (!loc[t][0])
          loc[t][0] = num[i][j];
        else
          loc[t][1] = num[i][j];
      }
  dfs(1, 1);
  printf("%I64d\n", (long long)ans * 5040);
  for (i = 1; i <= n; ++i) puts(res[i] + 1);
  return 0;
}
