#include <bits/stdc++.h>
using namespace std;
string c[20] = {"2", "3", "4", "5", "6", "7", "8",
                "9", "T", "J", "Q", "K", "A"},
       c2[10] = {"C", "D", "H", "S"};
int cl = 13, c2l = 4, n, m, x[4], y[4], l = 0;
char seenf;
bool ch[40][10], J[4];
string s[20][20];
bool checkgood(int i, int j) {
  bool ch2 = 1, ch = 1, ch3[40] = {};
  char suit = s[i][j][0];
  for (int g = i; g < i + 3; g++)
    for (int h = j; h < j + 3; h++) {
      string t = s[g][h];
      char t1 = t[0];
      int k;
      for (int g = 0; g < cl; g++)
        if (t1 == c[g][0]) {
          k = g;
          g = cl;
        }
      if (ch3[k]) ch2 = 0;
      ch3[k] = 1;
      if (t[1] != suit) ch = 0;
    }
  return (ch | ch2);
}
void mark(string t) {
  char a = t[0];
  char suit = t[1];
  int aa, sa;
  for (int i = 0; i < cl; i++)
    if (a == c[i][0]) aa = i;
  for (int j = 0; j < c2l; j++)
    if (suit == c2[j][0]) sa = j;
  ch[aa][sa] = 1;
}
bool checkedgham(int i, int j, int h, int g) {
  bool ch[50][50] = {};
  for (int g = i; g < i + 3; g++)
    for (int h = j; h < j + 3; h++) ch[g][h] = 1;
  for (int i = h; i < h + 3; i++)
    for (int j = g; j < g + 3; j++) {
      if (ch[i][j]) return 0;
      ch[i][j] = 1;
    }
  return 1;
}
bool check() {
  for (int i = 0; i < n - 2; i++)
    for (int j = 0; j < m - 2; j++)
      for (int h = 0; h < n - 2; h++)
        for (int g = 0; g < m - 2; g++) {
          if (!checkedgham(i, j, h, g)) continue;
          if (checkgood(i, j) && checkgood(h, g)) {
            cout << "Solution exists." << endl;
            if (l == 0)
              cout << "There are no jokers." << endl;
            else {
              if (l == 1) {
                cout << "Replace ";
                if (J[1])
                  cout << "J1";
                else
                  cout << "J2";
                cout << " with " << s[x[0]][y[0]] << '.' << endl;
              }
              if (l == 2) {
                if (seenf == '2') {
                  swap(x[0], x[1]);
                  swap(y[0], y[1]);
                }
                cout << "Replace J1 with " << s[x[0]][y[0]] << " and J2 with "
                     << s[x[1]][y[1]] << '.' << endl;
              }
            }
            cout << "Put the first square to (" << i + 1 << ", " << j + 1
                 << ")." << endl;
            cout << "Put the second square to (" << h + 1 << ", " << g + 1
                 << ")." << endl;
            exit(0);
            return 1;
          }
        }
  return 0;
}
void replaceJ(int k, int g, int o) {
  if (o == 0) {
    check();
    return;
  }
  for (int i = 0; i < cl; i++)
    for (int j = 0; j < c2l; j++)
      if (!ch[i][j] && !(i == k && j == g)) {
        s[x[o - 1]][y[o - 1]] = c[i] + c2[j];
        replaceJ(i, j, o - 1);
      }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> s[i][j];
      bool k = 1;
      if (s[i][j][0] == 'J' && (s[i][j][1] == '1' || s[i][j][1] == '2')) {
        if (!seenf) seenf = s[i][j][1];
        k = 0;
        if (s[i][j][1] == '1')
          J[1] = 1;
        else
          J[2] = 1;
        x[l] = i;
        y[l++] = j;
      }
      if (k) mark(s[i][j]);
    }
  replaceJ(-1, -1, l);
  cout << "No solution." << endl;
  return 0;
}
