#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, A = 1e3 + 2;
int n, m;
bool taken[52];
vector<string> all(52);
vector<pair<int, int>> jokers;
vector<vector<string>> in, tmp;
void input() {
  cin >> n >> m;
  in.resize(n, vector<string>(m));
  tmp.resize(n, vector<string>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> in[i][j];
  }
}
void pre() {
  string rank = "23456789TJQKA", type = "CDHS";
  int ptr = 0;
  for (int i = 0; i < 13; i++) {
    for (int j = 0; j < 4; j++, ptr++) {
      all[ptr].push_back(rank[i]);
      all[ptr].push_back(type[j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      tmp[i][j] = in[i][j];
      if (in[i][j] == "J1" || in[i][j] == "J2")
        jokers.push_back({i, j});
      else {
        for (int ind = 0; ind < 52; ind++) {
          if (in[i][j] == all[ind]) taken[ind] = 1;
        }
      }
    }
  }
}
bool validate(vector<vector<string>> &v, pair<int, int> &x1,
              pair<int, int> &x2) {
  vector<pair<int, int>> valid;
  for (int i = 0; i < n - 2; i++) {
    for (int j = 0; j < m - 2; j++) {
      set<char> ranks;
      for (int r = i; r < i + 3; r++) {
        for (int c = j; c < j + 3; c++) ranks.insert(v[r][c][0]);
      }
      if (ranks.size() == 9) valid.push_back({i, j});
    }
  }
  if (valid.empty()) return 0;
  pair<int, int> mni = {1e2, 0}, mnj = {0, 1e2};
  pair<int, int> mxi = {-1, 0}, mxj = {0, -1};
  for (auto x : valid) {
    if (mni.first > x.first) mni = x;
    if (mnj.second > x.second) mnj = x;
    if (mxi.first < x.first) mxi = x;
    if (mxj.second < x.second) mxj = x;
  }
  if (mxi.first - mni.first >= 3) {
    x1 = mxi, x2 = mni;
    return 1;
  }
  if (mxj.second - mnj.second >= 3) {
    x1 = mxj, x2 = mnj;
    return 1;
  }
  return 0;
}
void solved(pair<int, int> &p1, pair<int, int> &p2) {
  cout << "Solution exists.\n";
  if (jokers.size() == 0) cout << "There are no jokers.\n";
  if (jokers.size() == 1)
    cout << "Replace " << in[jokers[0].first][jokers[0].second] << " with "
         << tmp[jokers[0].first][jokers[0].second] << ".\n";
  if (jokers.size() == 2) {
    if (in[jokers[0].first][jokers[0].second] == "J2") {
      swap(in[jokers[0].first][jokers[0].second],
           in[jokers[1].first][jokers[1].second]);
      swap(tmp[jokers[0].first][jokers[0].second],
           tmp[jokers[1].first][jokers[1].second]);
    }
    cout << "Replace " << in[jokers[0].first][jokers[0].second] << " with "
         << tmp[jokers[0].first][jokers[0].second] << " and "
         << in[jokers[1].first][jokers[1].second] << " with "
         << tmp[jokers[1].first][jokers[1].second] << ".\n";
  }
  cout << "Put the first square to (" << p1.first + 1 << ", " << p1.second + 1
       << ").\n";
  cout << "Put the second square to (" << p2.first + 1 << ", " << p2.second + 1
       << ").\n";
  exit(0);
}
void generate(int ind) {
  if (ind == (int)jokers.size()) {
    pair<int, int> p1, p2;
    if (validate(tmp, p1, p2)) solved(p1, p2);
    return;
  }
  for (int i = 0; i < 52; i++) {
    if (!taken[i]) {
      taken[i] = 1;
      tmp[jokers[ind].first][jokers[ind].second] = all[i];
      generate(ind + 1);
      taken[i] = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input();
  pre();
  generate(0);
  cout << "No solution.\n";
  return 0;
}
