#include <bits/stdc++.h>
using namespace std;
long long fpm(long long b, long long e, long long m) {
  long long t = 1;
  for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
  return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class edge>
struct Graph {
  vector<vector<edge> > adj;
  Graph(int n) {
    adj.clear();
    adj.resize(n + 5);
  }
  Graph() { adj.clear(); }
  void resize(int n) { adj.resize(n + 5); }
  void add(int s, edge e) { adj[s].push_back(e); }
  void del(int s, edge e) {
    adj[s].erase(find((adj[s]).begin(), (adj[s]).end(), e));
  }
  int deg(int v) { return adj[v].size(); }
  vector<edge> &operator[](int t) { return adj[t]; }
};
const int maxn = 33, maxv = 16;
Graph<int> G(maxv);
char S[maxn][maxn];
bool saved = false;
int col[maxv], bak[maxv];
int o[maxv][maxv], tms, ans;
int rep[maxn][maxn];
vector<pair<int, int> > vec;
void search(int x) {
  if (x > 14) {
    ++tms;
    for (int v = 1; v <= 14; ++v)
      for (__typeof__((G[v]).begin()) e = (G[v]).begin(); e != (G[v]).end();
           ++e) {
        if (o[col[v]][col[*e]] == tms) return;
        o[col[v]][col[*e]] = o[col[*e]][col[v]] = tms;
      }
    if (!saved) memcpy(bak, col, sizeof(bak));
    ++ans, saved = true;
    return;
  }
  if (~col[x]) return search(x + 1);
  int z = 0;
  for (__typeof__((G[x]).begin()) e = (G[x]).begin(); e != (G[x]).end(); ++e)
    if (col[*e] != -1) z |= 1 << col[*e];
  z ^= 127;
  for (int i = 0; i <= 6; ++i)
    if (z >> i & 1) col[x] = i, search(x + 1);
  col[x] = -1;
}
void dfs(int x, int now) {
  if (x == (int)((vec).size())) return now == 7 ? search(1) : (void)0;
  dfs(x + 1, now);
  if (col[vec[x].first] == -1 && col[vec[x].second] == -1 && now <= 6) {
    col[vec[x].first] = now, col[vec[x].second] = now;
    dfs(x + 1, now + 1);
    col[vec[x].first] = -1, col[vec[x].second] = -1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, tot = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> (S[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (S[i][j] != '.' && !rep[i][j]) {
        ++tot;
        for (int x = 0; x < 2; ++x)
          for (int y = 0; y < 2; ++y) rep[i + x][j + y] = tot;
      }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) cerr << rep[i][j] << " ";
    cerr << endl;
  }
  int cnt = 0;
  memset(col, -1, sizeof(col));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (S[i][j] != '.')
        for (int x = 0, y = 1; x <= 1; ++x, --y)
          if (S[i][j] == S[i + x][j + y]) {
            if (rep[i][j] == rep[i + x][j + y])
              col[rep[i][j]] = cnt++, cerr << rep[i][j] << endl;
            else
              G.add(rep[i][j], rep[i + x][j + y]);
          }
  for (int i = 1; i <= 14; ++i)
    for (int j = 1; j <= 14; ++j)
      if (count((G[i]).begin(), (G[i]).end(), j) == 1)
        vec.push_back(make_pair(i, j)),
            cerr << "pushed: " << i << " " << j << endl;
  dfs(0, cnt);
  cout << ans * 5040 << endl;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      if (S[i][j] != '.')
        cout << bak[rep[i][j]];
      else
        cout << ".";
    cout << endl;
  }
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  return 0;
}
