#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int N = 222;
VPII Rotate(VPII cells) {
  for (auto& p : cells) {
    p = {-p.nd, p.st};
  }
  sort(ALL(cells));
  return cells;
}
VPII MirrorY(VPII cells) {
  for (auto& p : cells) {
    p = {-p.st, p.nd};
  }
  sort(ALL(cells));
  return cells;
}
VPII ShiftToQ1(VPII cells) {
  int mi = N, mj = N;
  for (auto p : cells) {
    mini(mi, p.st);
    mini(mj, p.nd);
  }
  for (auto& p : cells) {
    p.st -= mi;
    p.nd -= mj;
  }
  sort(ALL(cells));
  return cells;
}
VPII ShiftTo00(VPII cells) {
  int mi = cells[0].st;
  int mj = cells[0].nd;
  for (auto& p : cells) {
    p.st -= mi;
    p.nd -= mj;
  }
  return cells;
}
VPII Unambiguous(VPII cells) {
  cells = ShiftToQ1(cells);
  vector<VPII> que{cells};
  set<VPII> secik{cells};
  for (int ii = 0; ii < SZ(que); ii++) {
    auto v = que[ii];
    VPII cand1 = ShiftToQ1(Rotate(v));
    VPII cand2 = ShiftToQ1(MirrorY(v));
    vector<VPII> cands{cand1, cand2};
    for (auto cand : cands) {
      if (secik.count(cand)) { continue; }
      secik.insert(cand);
      que.PB(cand);
    }
  }
  //debug(orig, *secik.begin());
  return *secik.begin();
}

vector<VPII> GenAll(VPII cells) {
  cells = ShiftToQ1(cells);
  vector<VPII> que{cells};
  set<VPII> secik{cells};
  for (int ii = 0; ii < SZ(que); ii++) {
    auto v = que[ii];
    VPII cand1 = ShiftToQ1(Rotate(v));
    VPII cand2 = ShiftToQ1(MirrorY(v));
    vector<VPII> cands{cand1, cand2};
    for (auto cand : cands) {
      if (secik.count(cand)) { continue; }
      secik.insert(cand);
      que.PB(cand);
    }
  }
  return que;
}

// struct Tile {
//   VPII cells;
//   void UnambiguousSelf() {
//     
//   }
// };

int h, w;
bool IsInBig(int i, int j) {
  return i >= 1 && i <= 2 * h && j >= 1 && j <= 2 * w;
}
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
char big_board[N][N];
int vis[N][N];
void DfsBig(int i, int j, VPII& poses) {
  poses.PB({i, j});
  vis[i][j] = 1;
  REP (dir, 4) {
    int ni = i + di[dir];
    int nj = j + dj[dir];
    if (IsInBig(ni, nj) && big_board[ni][nj] == big_board[i][j] && !vis[ni][nj]) {
      DfsBig(ni, nj, poses);
    }
  }
}

vector<PII> cells_order;
bool IsOnBoard(int i, int j) {
  return i >= 1 && i <= h && j >= 1 && j <= w;
}

void PrintBoard(vector<vector<int>> board) {
  vector<vector<char>> ans(h + 1, vector<char>(w + 1, '.'));
  RE (i, h) {
    RE (j, w) {
      if (ans[i][j] != '.') { continue; }
      if (board[i][j] == 0) { continue; }
      VPII all_my_cells;
      RE (ii, h) {
        RE (jj, w) {
          if (board[i][j] == board[ii][jj]) {
            all_my_cells.PB({ii, jj});
          }
        }
      }
      set<char> neis_lets;
      for (auto p : all_my_cells) {
        REP (dir, 4) {
          int ni = p.st + di[dir];
          int nj = p.nd + dj[dir];
          if (IsOnBoard(ni, nj) && ans[ni][nj] != '.') {
            neis_lets.insert(ans[ni][nj]);
          }
        }
      }
      char let;
      FOR (c, 'A', 'Z') {
        if (neis_lets.count(c) == 0) {
          let = c;
          break;
        }
      }
      for (auto p : all_my_cells) {
        ans[p.st][p.nd] = let;
      }
    }
  }
  debug("lol", h, w);
  RE (i, h) {
    RE (j, w) {
      cout<<ans[i][j];
    }
    cout<<endl;
  }
  fflush(stdout);
  //assert(false);
}

void Try(map<VPII, int> cnt_map) {
  vector<vector<int>> board(h + 1, VI(w + 1));
  int rem_area = h * w;
  vector<pair<VPII, int>> cnt(ALL(cnt_map));
  sort(ALL(cnt), [&](pair<VPII, int> L, pair<VPII, int> R) { if (SZ(L.st) != SZ(R.st)) { return SZ(L.st) > SZ(R.st); } else { return L < R; }});
  VI thres{0, 12, 17, SZ(cnt)};
  VI tries{30, 15, 19};
  int nxt_ind = 1;
  for (auto nxt_cell : cells_order) {
    if (rem_area < 0) { break; }
    int i = nxt_cell.st;
    int j = nxt_cell.nd;
    if (board[i][j]) { continue; }
    int zero_cnt = 0, bad_pos = 0;
    REP (phase, 3) {
      int L = thres[phase];
      int R = thres[phase + 1];
      REP (try_ind, tries[phase]) {
        int tile_ind = L + rand() % (R - L);
        if (cnt[tile_ind].nd == 0) { zero_cnt++; continue; }
        vector<VPII> all_poss = GenAll(cnt[tile_ind].st);
        random_shuffle(ALL(all_poss));
        for (auto poss : all_poss) {
          for (auto shift : poss) {
            auto nposs = poss;
            for (auto& p : nposs) {
              p.st -= shift.st;
              p.nd -= shift.nd;
            }
            int fail = 0;
            for (auto cell : nposs) {
              int ni = i + cell.st;
              int nj = j + cell.nd;
              if (!IsOnBoard(ni, nj) || board[ni][nj]) { fail = 1; break; }
            }
            if (fail) {
              bad_pos++;
              continue;
            }
            for (auto cell : nposs) {
              int ni = i + cell.st;
              int nj = j + cell.nd;
              board[ni][nj] = nxt_ind;
            }
            set<PII> neis;
            for (auto cell : nposs) {
              int ni = i + cell.st;
              int nj = j + cell.nd;
              REP (dir, 8) {
                int nni = ni + di[dir];
                int nnj = nj + dj[dir];
                if (IsOnBoard(nni, nnj) && board[nni][nnj] == 0) {
                  neis.insert({nni, nnj});
                }
              }
            }
//             if (neis.empty()) {
//               debug(nxt_cell);
//               PrintBoard(board);
//             }
            if (neis.empty()) { assert(rem_area == SZ(nposs)); goto Dupa; }
            assert(!neis.empty());
            vector<PII> que{*neis.begin()};
            map<PII, int> vis_neis;
            vis_neis[{que[0].st, que[0].nd}] = 1;
            for (int ii = 0; ii < SZ(que); ii++) {
              int ci = que[ii].st;
              int cj = que[ii].nd;
              REP (dir, 4) {
                int ni = ci + di[dir];
                int nj = cj + dj[dir];
                if (neis.count({ni, nj})) {
                  if (vis_neis[{ni, nj}] == 0) {
                    vis_neis[{ni, nj}] = 1;
                    que.PB({ni, nj});
                  }
                }
              }
            }
            if (SZ(que) == SZ(neis)) {
              cnt[tile_ind].nd--;
              rem_area -= SZ(cnt[tile_ind].st);
              goto End;
            }
//             PrintBoard(board);
//             debug(neis);
//             debug(que);
            for (auto cell : nposs) {
              int ni = i + cell.st;
              int nj = j + cell.nd;
              board[ni][nj] = 0;
            }
          }
        }
      } 
    }
//     PrintBoard(board);
//     debug("fail", bad_pos, zero_cnt, nxt_cell);
//     for (auto p : cnt) {
//       debug(p.nd, p.st);
//     }
    return;
    End: ;
    nxt_ind++;
  }
  Dupa: ;
  debug("start bt");
  
  
  debug("we're good");
  PrintBoard(board);
  exit(0);
}
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  cin>>h>>w;
  
  RE (i, h) {
    RE (j, w) {
      cells_order.PB({i, j});
    }
  }
  sort(ALL(cells_order), [&](PII L, PII R) {
    int mL = min(L.st + w, L.nd + h), mR = min(R.st + w, R.nd + h); 
    if (mL != mR) {
      return mL < mR;
    }
    return L < R;
  });
  //debug(cells_order);
  
  RE (i, 2 * h) {
    RE (j, 2 * w) {
      cin>>big_board[i][j];
    }
  }
  map<VPII, int> cnt;
  int cnt_tiles = 0;
  int cnt_cells = 0;
  VI cnt_by_sz(7);
  RE (i, 2 * h) {
    RE (j, 2 * w) {
      if (big_board[i][j] == '.') { continue; }
      if (vis[i][j]) { continue; }
      VPII pos;
      DfsBig(i, j, pos);
      pos = Unambiguous(pos);
      cnt_cells += SZ(pos);
      cnt_by_sz[SZ(pos)]++;
      cnt_tiles++;
      cnt[pos]++;
    }
  }
//   debug(cnt_tiles, h * w);
//   debug(cnt);
//   debug(SZ(cnt));
//   for (auto p : cnt) {
//     vector<vector<char>> visu(5, vector<char>(5, '.'));
//     for (auto para : p.st) {
//       visu[para.st][para.nd] = '#';
//     }
//     REP (i, 5) {
//       REP (j, 5) {
//         cerr<<visu[i][j];
//       }
//       cerr<<endl;
//     }
//     cerr<<p.nd<<endl;
//   }
//   Try(cnt);
  while (1) {
    Try(cnt);
  }
  
  return 0;
}
