#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long n, m, joker1 = 0, joker2 = 0;
string mas[18][18];
string cards = "23456789TJQKA";
set<string> av;
bool check(long long x, long long y, string j1, string j2) {
  set<char> type, val;
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 3; j++) {
      auto cur = mas[x + i][y + j];
      if (cur == "J1") cur = j1;
      if (cur == "J2") cur = j2;
      val.insert(cur[0]);
      type.insert(cur[1]);
    }
  }
  return val.size() == 9 || type.size() == 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < cards.size(); i++) {
    string cur = cards.substr(i, 1);
    av.insert(cur + "C");
    av.insert(cur + "D");
    av.insert(cur + "H");
    av.insert(cur + "S");
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> mas[i][j];
      if (mas[i][j] == "J1") joker1 = 1;
      if (mas[i][j] == "J2") joker2 = 1;
      av.erase(mas[i][j]);
    }
  }
  for (auto j1 : av) {
    for (auto j2 : av) {
      if (j1 == j2) continue;
      vector<pair<long long, long long> > p;
      for (long long i = 0; i < n - 2; i++) {
        for (long long j = 0; j < m - 2; j++) {
          if (check(i, j, j1, j2)) p.push_back({i, j});
        }
      }
      for (long long i = 0; i < p.size(); i++) {
        for (long long j = 0; j < p.size(); j++) {
          if (i == j) continue;
          if (abs(p[i].first - p[j].first) >= 3 ||
              abs(p[i].second - p[j].second) >= 3) {
            cout << "Solution exists.\n";
            if (!joker1 && !joker2)
              cout << "There are no jokers.\n";
            else if (joker1 ^ joker2) {
              if (joker1) cout << "Replace J1 with " << j1 << ".\n";
              if (joker2) cout << "Replace J2 with " << j2 << ".\n";
            } else
              cout << "Replace J1 with " << j1 << " and J2 with " << j2
                   << ".\n";
            cout << "Put the first square to (" << p[i].first + 1 << ", "
                 << p[i].second + 1 << ").\n";
            cout << "Put the second square to (" << p[j].first + 1 << ", "
                 << p[j].second + 1 << ").\n";
            return 0;
          }
        }
      }
    }
  }
  cout << "No solution.";
  return 0;
}
