#include <bits/stdc++.h>
using namespace std;
vector<string> t;
string a[] = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
string b[] = {"C", "D", "H", "S"};
int n, m;
void gen() {
  for (int i = 0; i < 13; ++i)
    for (int j = 0; j < 4; ++j) t.push_back(a[i] + b[j]);
}
int Szukaj(string x) {
  for (int i = 0; i < 52; ++i)
    if (t[i] == x) return i;
}
void Spr(vector<vector<string> >& k, int* x1, int* y1, int* x2, int* y2) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int l = 0; l < n; ++l) {
        for (int o = 0; o < m; ++o) {
          if (i + 2 < n && j + 2 < m && l + 2 < n && o + 2 < m &&
              !(abs(i - l) <= 2 && abs(j - o) <= 2)) {
            set<char> suit1, rank1;
            for (int x = i; x <= i + 2; ++x) {
              for (int y = j; y <= j + 2; ++y) {
                rank1.insert(k[x][y][0]);
                suit1.insert(k[x][y][1]);
              }
            }
            set<char> suit2, rank2;
            for (int x = l; x <= l + 2; ++x) {
              for (int y = o; y <= o + 2; ++y) {
                rank2.insert(k[x][y][0]);
                suit2.insert(k[x][y][1]);
              }
            }
            if ((suit1.size() == 1 || rank1.size() == 9) &&
                (suit2.size() == 1 || rank2.size() == 9)) {
              *x1 = i;
              *y1 = j;
              *x2 = l;
              *y2 = o;
              return;
            }
          }
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  gen();
  cin >> n >> m;
  vector<vector<string> > k(n, vector<string>(m));
  int joker = 0;
  int jx1 = -1, jy1 = -1, jx2 = -1, jy2 = 0;
  vector<bool> jest(52, false);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> k[i][j];
      if (k[i][j] != "J1" && k[i][j] != "J2") jest[Szukaj(k[i][j])] = true;
      if (k[i][j] == "J1") {
        jx1 = i;
        jy1 = j;
        ++joker;
      }
      if (k[i][j] == "J2") {
        jx2 = i;
        jy2 = j;
        ++joker;
      }
    }
  }
  int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
  if (joker == 0) {
    Spr(k, &x1, &y1, &x2, &y2);
    if (x1 != -1) {
      cout << "Solution exists." << endl;
      cout << "There are no jokers." << endl;
      cout << "Put the first square to (" << x1 + 1 << ", " << y1 + 1 << ")."
           << endl;
      cout << "Put the second square to (" << x2 + 1 << ", " << y2 + 1 << ").";
    } else
      cout << "No solution.";
  }
  if (joker == 1) {
    bool ok = false;
    if (jx1 != -1) {
      for (int i = 0; i < t.size(); ++i) {
        if (!jest[i]) {
          k[jx1][jy1] = t[i];
          Spr(k, &x1, &y1, &x2, &y2);
          if (x1 != -1) {
            cout << "Solution exists." << endl;
            cout << "Replace J1 with " << t[i] << "." << endl;
            cout << "Put the first square to (" << x1 + 1 << ", " << y1 + 1
                 << ")." << endl;
            cout << "Put the second square to (" << x2 + 1 << ", " << y2 + 1
                 << ").";
            ok = true;
            break;
          }
        }
      }
      if (!ok) cout << "No solution.";
    }
    if (jx2 != -1) {
      for (int i = 0; i < t.size(); ++i) {
        if (!jest[i]) {
          k[jx2][jy2] = t[i];
          Spr(k, &x1, &y1, &x2, &y2);
          if (x1 != -1) {
            cout << "Solution exists." << endl;
            cout << "Replace J2 with " << t[i] << "." << endl;
            cout << "Put the first square to (" << x1 + 1 << ", " << y1 + 1
                 << ")." << endl;
            cout << "Put the second square to (" << x2 + 1 << ", " << y2 + 1
                 << ").";
            ok = true;
            break;
          }
        }
      }
      if (!ok) cout << "No solution.";
    }
  }
  if (joker == 2) {
    bool ok = false;
    for (int i = 0; i < t.size(); ++i) {
      for (int j = 0; j < t.size(); ++j) {
        if (!jest[i] && !jest[j] && i != j) {
          k[jx1][jy1] = t[i];
          k[jx2][jy2] = t[j];
          Spr(k, &x1, &y1, &x2, &y2);
          if (x1 != -1) {
            cout << "Solution exists." << endl;
            cout << "Replace J1 with " << t[i] << " and J2 with " << t[j] << "."
                 << endl;
            cout << "Put the first square to (" << x1 + 1 << ", " << y1 + 1
                 << ")." << endl;
            cout << "Put the second square to (" << x2 + 1 << ", " << y2 + 1
                 << ").";
            ok = true;
            break;
          }
        }
      }
      if (ok) break;
    }
    if (!ok) cout << "No solution.";
  }
  return 0;
}
