#include <bits/stdc++.h>
using namespace std;
vector<string> ranks = {"2", "3", "4", "5", "6", "7", "8",
                        "9", "T", "J", "Q", "K", "A"};
vector<string> suits = {"C", "D", "H", "S"};
set<string> karty;
string tab[28][28];
int R, C;
bool war1(int y, int x) {
  set<char> suits;
  for (int i = y; i < y + 3; ++i)
    for (int j = x; j < x + 3; ++j) suits.insert(tab[i][j][1]);
  return suits.size() == 1;
}
bool war2(int y, int x) {
  set<char> ranks;
  for (int i = y; i < y + 3; ++i)
    for (int j = x; j < x + 3; ++j) {
      ranks.insert(tab[i][j][0]);
    }
  return ranks.size() == 9;
}
bool czyok[18][18];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (auto &p : ranks)
    for (auto &pp : suits) karty.insert(p + pp);
  cin >> R >> C;
  pair<long long, long long> jokery[2] = {{19, 19}, {19, 19}};
  int ile_jokerow = 0;
  for (int i = 0; i < R; ++i)
    for (int j = 0; j < C; ++j) {
      cin >> tab[i][j];
      if (tab[i][j][1] == '1' || tab[i][j][1] == '2') {
        if (tab[i][j][1] == '1')
          jokery[0] = {i, j};
        else
          jokery[1] = {i, j};
        ++ile_jokerow;
      } else
        karty.erase(karty.find(tab[i][j]));
    }
  for (auto it = karty.begin(); it != karty.end(); ++it) {
    for (auto itt = karty.begin(); itt != karty.end(); ++itt) {
      if (it == itt) continue;
      tab[jokery[0].first][jokery[0].second] = *it;
      tab[jokery[1].first][jokery[1].second] = *itt;
      for (int pos = 0; pos <= R * C; ++pos) {
        int y = pos / C;
        int x = pos % C;
        if (y + 2 >= R || x + 2 >= C) continue;
        if (war1(y, x) || war2(y, x))
          for (int pos2 = pos + 1; pos2 <= R * C; ++pos2) {
            int yy = pos2 / C;
            int xx = pos2 % C;
            if (yy + 2 >= R || xx + 2 >= C ||
                (abs(y - yy) < 3 && abs(x - xx) < 3))
              continue;
            if (war1(yy, xx) || war2(yy, xx)) {
              cout << "Solution exists.\n";
              if (ile_jokerow == 1) {
                if (jokery[1].first == 19)
                  cout << "Replace J1 with "
                       << tab[jokery[0].first][jokery[0].second] << ".\n";
                else
                  cout << "Replace J2 with "
                       << tab[jokery[0].first][jokery[0].second] << ".\n";
              } else if (ile_jokerow == 2) {
                cout << "Replace J1 with "
                     << tab[jokery[0].first][jokery[0].second]
                     << " and J2 with "
                     << tab[jokery[1].first][jokery[1].second] << ".\n";
              } else
                cout << "There are no jokers.\n";
              cout << "Put the first square to (" << y + 1 << ", " << x + 1
                   << ").\n";
              cout << "Put the second square to (" << yy + 1 << ", " << xx + 1
                   << ").\n";
              return 0;
            }
          }
      }
    }
  }
  cout << "No solution.";
  return 0;
}
