#include <bits/stdc++.h>
using namespace std;
const string ssuit[4] = {"C", "D", "H", "S"};
const string rrank[13] = {"2", "3", "4", "5", "6", "7", "8",
                          "9", "T", "J", "Q", "K", "A"};
set<string> cards, jok1, jok2;
set<char> suit, Rank;
map<char, int> mp;
string card[100][100];
int n, m, ci, cj, ck, cl;
void get_cards() {
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 13; ++j) cards.insert(rrank[j] + ssuit[i]);
}
bool square(int i, int j) { return i + 2 < n && j + 2 < m; }
bool overlap(int i, int j) {
  int ci2 = ci + 2, cj2 = cj + 2, ni, nj;
  for (int l = 0; l <= 2; l += 2)
    for (int k = 0; k <= 2; k += 2) {
      ni = i + l;
      nj = j + k;
      if (ni >= ci && ni <= ci2 && nj >= cj && nj <= cj2) {
        return 1;
      }
    }
  return 0;
}
bool valid_square(int r, int c, string jak1, string jak2) {
  suit.clear();
  Rank.clear();
  for (int i = r; i <= r + 2; i++) {
    for (int j = c; j <= c + 2; j++) {
      string cur = card[i][j];
      if (cur == "J1") cur = jak1;
      if (cur == "J2") cur = jak2;
      Rank.insert(cur[0]);
      suit.insert(cur[1]);
    }
  }
  return Rank.size() == 9 || suit.size() == 1;
}
bool check(string jak1, string jak2) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (square(i, j) && valid_square(i, j, jak1, jak2)) {
        ci = i;
        cj = j;
        for (int k = 0; k < n; k++) {
          for (int l = 0; l < m; l++) {
            if (square(k, l) && !overlap(k, l) &&
                valid_square(k, l, jak1, jak2)) {
              ck = k;
              cl = l;
              return 1;
            }
          }
        }
      }
    }
  }
  return 0;
}
int main() {
  get_cards();
  cin >> n >> m;
  bool j1 = 0, j2 = 0;
  jok1.insert("a");
  jok2.insert("b");
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> card[i][j];
      if (card[i][j] == "J1") j1 = 1;
      if (card[i][j] == "J2") j2 = 1;
      cards.erase(card[i][j]);
    }
  if (j1) jok1 = cards;
  if (j2) jok2 = cards;
  for (auto a : jok1) {
    for (auto b : jok2) {
      if (a != b && check(a, b) && a != "J1" && b != "J2") {
        cout << "Solution exists." << endl;
        if (j1 && j2)
          cout << "Replace J1 with " << a << " and J2 with " << b << "."
               << endl;
        else if (j1)
          cout << "Replace J1 with " << a << "." << endl;
        else if (j2)
          cout << "Replace J2 with " << b << "." << endl;
        else
          cout << "There are no jokers." << endl;
        cout << "Put the first square to (" << ci + 1 << ", " << cj + 1 << ")."
             << endl;
        cout << "Put the second square to (" << ck + 1 << ", " << cl + 1 << ")."
             << endl;
        return 0;
      }
    }
  }
  cout << "No solution." << endl;
  return 0;
}
