#include <bits/stdc++.h>
using namespace std;
using namespace std;
char s[50], b[50][50];
vector<int> a[30];
int n, m, t, ans, x, y;
int c[50][50], v[50], f[30][30];
bool check() {
  memset(f, 0, sizeof f);
  for (int i = 0; i < 28; 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 == 15) {
    if (check()) {
      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] != -1)
    dfs(x + 1, y);
  else {
    v[x] = y;
    for (int i = 1; i < 15; i++)
      if (v[i] == -1) {
        v[i] = y;
        dfs(x + 1, y + 1);
        v[i] = -1;
      }
    v[x] = -1;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> (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);
  cout << ans * 5040 << '\n';
  for (int i = 1; i <= n; i++) puts(b[i] + 1);
  return 0;
}
