#include <bits/stdc++.h>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int N, M;
char S[35][35];
void Init() {
  Get(N);
  Get(M);
  for (int i = 1; i <= N; i++) gets(S[i] + 1);
}
int Pair[25];
int Visited[25];
int Ans;
int ID[25];
int First[35];
int Second[35];
int Used[15][15];
int Time;
int OK[35];
void Check() {
  Time++;
  for (int i = 1; i <= 28; i++) {
    if (Used[ID[First[i]]][ID[Second[i]]] == Time) return;
    Used[ID[First[i]]][ID[Second[i]]] = Used[ID[Second[i]]][ID[First[i]]] =
        Time;
  }
  Ans++;
  for (int i = 1; i <= 14; i++) OK[i] = ID[i];
}
void DFS(int X) {
  if (X > 14) {
    for (int i = 1; i <= 14; i++) ID[i] = 0;
    for (int i = 1, k = 0; i <= 14; i++)
      if (ID[i] == 0) {
        k++;
        ID[i] = ID[Pair[i]] = k;
      }
    Check();
    return;
  }
  if (Pair[X] != 0)
    DFS(X + 1);
  else {
    for (int i = X + 1; i <= 14; i++)
      if (Visited[i] == 0 && Visited[X] == 0) {
        Visited[i] = Visited[X] = 1;
        Pair[X] = i;
        Pair[i] = X;
        DFS(X + 1);
        Pair[X] = 0;
        Pair[i] = 0;
        Visited[i] = Visited[X] = 0;
      }
  }
}
int Belong[35][35];
void Work() {
  for (int i = 1, k = 0; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (S[i][j] != '.' && Belong[i][j] == 0) {
        k++;
        Belong[i][j] = k;
        Belong[i][j + 1] = k;
        Belong[i + 1][j] = k;
        Belong[i + 1][j + 1] = k;
      }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      if (S[i][j] == '.') continue;
      int ID;
      if (S[i][j] >= 'a' && S[i][j] <= 'z') {
        ID = S[i][j] - 'a' + 1;
      } else if (S[i][j] >= 'A' && S[i][j] <= 'Z') {
        ID = S[i][j] - 'A' + 1 + 26;
      }
      if (First[ID] == 0) {
        First[ID] = Belong[i][j];
      } else
        Second[ID] = Belong[i][j];
    }
  DFS(1);
}
void Output() {
  printf("%I64d\n", Ans * 7 * 6 * 5 * 4 * 3 * 2ll);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++)
      printf("%c", S[i][j] == '.' ? '.' : OK[Belong[i][j]] - 1 + '0');
    puts("");
  }
}
int main() {
  Init();
  Work();
  Output();
  return 0;
}
