#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  cout << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &x) {
  os << "[";
  for (int i = 0; i < (int)(x.size()); ++i) {
    os << x[i];
    if (i != x.size() - 1) os << ",";
  }
  os << "]";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
const int M = 34;
int n, m;
char c[M][M];
int cls[M][M];
vector<pair<int, int> > v;
vector<pair<int, int> > vp[30];
int to_id(char c) {
  if ('a' <= c and c <= 'z')
    return c - 'a';
  else
    return c - 'A' + 26;
}
pair<int, int> another(const pair<int, int> &p) {
  int i = c[p.first][p.second];
  if (p == vp[i][0])
    return vp[i][1];
  else if (p == vp[i][1])
    return vp[i][0];
  else
    assert(false);
}
int t[M];
vector<pair<int, int> > sq;
set<pair<int, int> > s;
stringstream ss;
int dir[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
int ans = 0;
bool output = true;
void find(int col) {
  if (col == 7) {
    ans++;
    if (output) {
      for (int i = 0; i < (int)(n); ++i) {
        for (int j = 0; j < (int)(m); ++j) {
          if (c[i][j] == -1)
            ss << ".";
          else
            ss << t[cls[i][j]];
        }
        ss << endl;
      }
      output = false;
    }
    return;
  }
  for (int i = 0; i < 14; i++) {
    if (t[i] != -1) continue;
    for (int j = i + 1; j < 14; j++) {
      if (t[j] != -1) continue;
      t[i] = t[j] = col;
      set<pair<int, int> > qu;
      bool valid = true;
      for (int d = 0; d < (int)(4); ++d) {
        pair<int, int> p2(sq[i].first + dir[d][0], sq[i].second + dir[d][1]);
        pair<int, int> q = another(p2);
        int cl = cls[q.first][q.second];
        if (t[cl] == -1) continue;
        pair<int, int> domi(col, t[cl]);
        if (domi.first > domi.second) swap(domi.first, domi.second);
        if ((i != cl and j != cl) or p2 < q) {
          if (s.find(domi) != s.end() or qu.find(domi) != qu.end())
            valid = false;
          else
            qu.insert(domi);
        }
      }
      for (int d = 0; d < (int)(4); ++d) {
        pair<int, int> p2(sq[j].first + dir[d][0], sq[j].second + dir[d][1]);
        pair<int, int> q = another(p2);
        int cl = cls[q.first][q.second];
        if (t[cl] == -1) continue;
        pair<int, int> domi(col, t[cl]);
        if (domi.first > domi.second) swap(domi.first, domi.second);
        if ((i != cl and j != cl) or p2 < q) {
          if (s.find(domi) != s.end() or qu.find(domi) != qu.end())
            valid = false;
          else
            qu.insert(domi);
        }
      }
      if (valid) {
        for (__typeof((qu).begin()) it = (qu).begin(); it != (qu).end(); ++it)
          s.insert(*it);
        find(col + 1);
        for (__typeof((qu).begin()) it = (qu).begin(); it != (qu).end(); ++it)
          s.erase(*it);
      }
      t[i] = t[j] = -1;
    }
    break;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(n); ++i) cin >> c[i];
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j)
      if (c[i][j] == '.')
        c[i][j] = -1;
      else
        c[i][j] = to_id(c[i][j]);
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j)
      if (c[i][j] >= 0) {
        vp[c[i][j]].push_back(make_pair(i, j));
      }
  memset(cls, -1, sizeof(cls));
  int clsct = 0;
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j)
      if (cls[i][j] == -1 and c[i][j] != -1) {
        sq.push_back(pair<int, int>(i, j));
        cls[i][j] = cls[i + 1][j] = cls[i + 1][j + 1] = cls[i][j + 1] = clsct++;
      }
  memset(t, -1, sizeof(t));
  find(0);
  cout << ans * 5040 << endl;
  cout << ss.str();
  return 0;
}
