#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const int N = 17 + 5;
const int xinc[] = {0, 0, 1, -1};
const int yinc[] = {1, -1, 0, 0};
const long double PI = acos(-1.0);
const double EPS = 1e-9;
int n, m, jcnt;
string a[N][N];
set<pair<int, int> > ans;
map<pair<int, int>, vector<pair<long long, long long> > > ma;
pair<int, int> _j1, j2;
set<string> present;
string suit[] = {"C", "D", "H", "S"};
string rnk[] = {"2", "3", "4", "5", "6", "7", "8",
                "9", "T", "J", "Q", "K", "A"};
bool valid(int r, int c) {
  set<char> suits;
  set<char> rnks;
  for (int i = r; i <= r + 2; i++)
    for (int j = c; j <= c + 2; j++) {
      suits.insert(a[i][j][1]);
      rnks.insert(a[i][j][0]);
    }
  return (rnks.size() == 9 || suits.size() == 1);
}
set<string> cards;
void solve() {
  cin >> n >> m;
  for (int i = 0; i < 13; i++)
    for (int j = 0; j < 4; j++) cards.insert(rnk[i] + suit[j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == "J1") _j1 = make_pair(i, j), jcnt++;
      if (a[i][j] == "J2") j2 = make_pair(i, j), jcnt++;
      cards.erase(a[i][j]);
    }
  if (jcnt == 0) {
    for (int i = 1; i <= n - 2; i++)
      for (int j = 1; j <= m - 2; j++)
        if (valid(i, j)) ans.insert(make_pair(i, j));
    for (auto i : ans)
      for (auto j : ans)
        if (!(abs(i.first - j.first) < 3 && abs(i.second - j.second) < 3)) {
          cout << "Solution exists." << '\n';
          cout << "There are no jokers." << '\n';
          cout << "Put the first square to (" << i.first << ", " << i.second
               << ")." << '\n';
          cout << "Put the second square to (" << j.first << ", " << j.second
               << ")." << '\n';
          return;
        }
  } else if (jcnt == 1) {
    for (auto i : cards) {
      bool p1 = false;
      if (_j1.first != 0)
        a[_j1.first][_j1.second] = i, p1 = true;
      else
        a[j2.first][j2.second] = i;
      ans.clear();
      for (int i = 1; i <= n - 2; i++)
        for (int j = 1; j <= m - 2; j++) {
          if (valid(i, j)) {
            ans.insert(make_pair(i, j));
          }
        }
      for (auto i : ans)
        for (auto j : ans)
          if (!(abs(i.first - j.first) < 3 && abs(i.second - j.second) < 3)) {
            cout << "Solution exists." << '\n';
            if (p1)
              cout << "Replace J1 with " << a[_j1.first][_j1.second] << "."
                   << '\n';
            else
              cout << "Replace J2 with " << a[j2.first][j2.second] << "."
                   << '\n';
            cout << "Put the first square to (" << i.first << ", " << i.second
                 << ")." << '\n';
            cout << "Put the second square to (" << j.first << ", " << j.second
                 << ")." << '\n';
            return;
          }
    }
  } else if (jcnt == 2) {
    for (auto i : cards)
      for (auto j : cards)
        if (i != j) {
          a[_j1.first][_j1.second] = i;
          a[j2.first][j2.second] = j;
          ans.clear();
          for (int i = 1; i <= n - 2; i++)
            for (int j = 1; j <= m - 2; j++)
              if (valid(i, j)) ans.insert(make_pair(i, j));
          for (auto i : ans)
            for (auto j : ans)
              if (!(abs(i.first - j.first) < 3 &&
                    abs(i.second - j.second) < 3)) {
                cout << "Solution exists." << '\n';
                cout << "Replace J1 with " << a[_j1.first][_j1.second]
                     << " and J2 with " << a[j2.first][j2.second] << "."
                     << '\n';
                cout << "Put the first square to (" << i.first << ", "
                     << i.second << ")." << '\n';
                cout << "Put the second square to (" << j.first << ", "
                     << j.second << ")." << '\n';
                return;
              }
        }
  }
  cout << "No solution." << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
