#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int n, m;
bool check_square(const vector<pair<int, int>> &have) {
  bool ok = 1;
  for (auto i : have)
    if (i.second != have[0].second) ok = 0;
  if (ok) return 1;
  vector<int> cnt(20);
  for (auto i : have) cnt[i.first]++;
  for (auto i : cnt)
    if (i > 1) return 0;
  return 1;
}
pair<pair<int, int>, pair<int, int>> get_squares(
    const vector<vector<pair<int, int>>> &g) {
  for (int x1 = 0; x1 < n - 2; ++x1) {
    for (int y1 = 0; y1 < m - 2; ++y1) {
      for (int x2 = 0; x2 < n - 2; ++x2) {
        for (int y2 = 0; y2 < m - 2; ++y2) {
          if (abs(x1 - x2) < 3 && abs(y1 - y2) < 3) continue;
          vector<pair<int, int>> h1, h2;
          for (int dx = 0; dx < 3; ++dx)
            for (int dy = 0; dy < 3; ++dy) {
              h1.push_back(g[x1 + dx][y1 + dy]);
              h2.push_back(g[x2 + dx][y2 + dy]);
            }
          if (check_square(h1) && check_square(h2)) return {{x1, y1}, {x2, y2}};
        }
      }
    }
  }
  return {{-1, -1}, {-1, -1}};
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> m;
  int cntj = 0;
  pair<int, int> jpos[2];
  string jstr[2];
  vector<vector<pair<int, int>>> g(n, vector<pair<int, int>>(m));
  vector<int> parsef(256, 16), parses(256, 16);
  for (int i = '2'; i <= '9'; ++i) parsef[i] = i - '2';
  parsef['T'] = 8;
  parsef['J'] = 9;
  parsef['Q'] = 10;
  parsef['K'] = 11;
  parsef['A'] = 12;
  parses['C'] = 0;
  parses['D'] = 1;
  parses['H'] = 2;
  parses['S'] = 3;
  vector<vector<bool>> used(20, vector<bool>(20));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      string s;
      cin >> s;
      if (s[1] == '1' || s[1] == '2') {
        jpos[cntj] = {i, j};
        jstr[cntj++] = s;
      } else {
        g[i][j] = {parsef[s[0]], parses[s[1]]};
        used[parsef[s[0]]][parses[s[1]]] = 1;
      }
    }
  vector<pair<int, int>> canchange;
  for (int i = 0; i < 13; ++i)
    for (int j = 0; j < 4; ++j)
      if (!used[i][j]) canchange.push_back({i, j});
  if (cntj == 0) {
    auto ans = get_squares(g);
    if (ans.first.first != -1) {
      cout << "Solution exists." << endl;
      cout << "There are no jokers." << endl;
      cout << "Put the first square to (" << ans.first.first + 1 << ", "
           << ans.first.second + 1 << ")." << endl;
      cout << "Put the second square to (" << ans.second.first + 1 << ", "
           << ans.second.second + 1 << ")." << endl;
      return 0;
    }
  } else if (cntj == 1) {
    for (auto changeto : canchange) {
      g[jpos[0].first][jpos[0].second] = changeto;
      auto ans = get_squares(g);
      if (ans.first.first != -1) {
        cout << "Solution exists." << endl;
        string parse = "##";
        for (int i = 0; i < 256; ++i) {
          if (parsef[i] == changeto.first) parse[0] = i;
          if (parses[i] == changeto.second) parse[1] = i;
        }
        cout << "Replace " << jstr[0] << " with " << parse << "." << endl;
        cout << "Put the first square to (" << ans.first.first + 1 << ", "
             << ans.first.second + 1 << ")." << endl;
        cout << "Put the second square to (" << ans.second.first + 1 << ", "
             << ans.second.second + 1 << ")." << endl;
        return 0;
      }
    }
  } else {
    for (int changef = 0; changef < canchange.size(); ++changef) {
      for (int changes = 0; changes < canchange.size(); ++changes) {
        if (changef == changes) continue;
        g[jpos[0].first][jpos[0].second] = canchange[changef];
        g[jpos[1].first][jpos[1].second] = canchange[changes];
        auto ans = get_squares(g);
        if (ans.first.first != -1) {
          cout << "Solution exists." << endl;
          string jf = "##", js = "##";
          for (int i = 0; i < 256; ++i) {
            if (parsef[i] == canchange[changef].first) jf[0] = i;
            if (parses[i] == canchange[changef].second) jf[1] = i;
            if (parsef[i] == canchange[changes].first) js[0] = i;
            if (parses[i] == canchange[changes].second) js[1] = i;
          }
          if (jstr[0] == "J2") swap(jf, js);
          cout << "Replace J1 with " << jf << " and J2 with " << js << "."
               << endl;
          cout << "Put the first square to (" << ans.first.first + 1 << ", "
               << ans.first.second + 1 << ")." << endl;
          cout << "Put the second square to (" << ans.second.first + 1 << ", "
               << ans.second.second + 1 << ")." << endl;
          return 0;
        }
      }
    }
  }
  cout << "No solution." << endl;
  return 0;
}
