#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<string>> mat;
set<string> st;
vector<string> rnk{"2", "3", "4", "5", "6", "7", "8",
                   "9", "T", "J", "Q", "K", "A"};
vector<string> suit{"C", "D", "H", "S"};
void printPos(const vector<pair<int, int>> &pos) {
  assert(pos.size() == 2);
  cout << "Put the first square to " << '(' << pos[0].first + 1 << ", "
       << pos[0].second + 1 << ").\n";
  cout << "Put the second square to " << '(' << pos[1].first + 1 << ", "
       << pos[1].second + 1 << ").\n";
}
int xx[] = {0, 0, 2, 2};
int yy[]{0, 2, 2, 0};
inline bool nonOverLap(const int a, const int b, const int c, const int d) {
  for (int h = 0; h < 4; ++h) {
    if (c + xx[h] >= a && c + xx[h] <= a + 2 && d + yy[h] >= b &&
        d + yy[h] <= b + 2)
      return false;
  }
  return true;
}
bool check(const int r, const int c) {
  set<char> stR, stS;
  for (int i = r; i <= r + 2; ++i) {
    for (int j = c; j <= c + 2; ++j) {
      stR.emplace(mat[i][j][0]);
      stS.emplace(mat[i][j][1]);
    }
  }
  if (stS.size() == 1) return true;
  return stR.size() == 9;
}
vector<pair<int, int>> getSquares() {
  for (int i = 0; i + 2 < n; ++i) {
    for (int j = 0; j + 2 < m; ++j) {
      for (int k = 0; k + 2 < n; ++k) {
        for (int l = 0; l + 2 < m; ++l) {
          if (nonOverLap(i, j, k, l)) {
            if (check(i, j) && check(k, l)) {
              vector<pair<int, int>> ans{{i, j}, {k, l}};
              return ans;
            }
          }
        }
      }
    }
  }
  return {{-1, -1}};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  for (int i = 0; i < (int)rnk.size(); ++i) {
    for (int j = 0; j < (int)suit.size(); ++j) {
      st.emplace(rnk[i] + suit[j]);
    }
  }
  cin >> n >> m;
  mat.assign(n, vector<string>(m, ""));
  pair<int, int> j1(-1, -1), j2(-1, -1);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mat[i][j];
      if (mat[i][j] == "J1")
        j1 = {i, j};
      else if (mat[i][j] == "J2")
        j2 = {i, j};
      else
        st.erase(mat[i][j]);
    }
  }
  if (j1.first != -1 && j2.first != -1) {
    for (const auto &it1 : st) {
      for (const auto &it2 : st) {
        if (it1 == it2) continue;
        mat[j1.first][j1.second] = it1;
        mat[j2.first][j2.second] = it2;
        vector<pair<int, int>> pos = getSquares();
        if (pos[0].first != -1) {
          cout << "Solution exists.\n";
          cout << "Replace J1 with " << it1 << " and J2 with " << it2 << ".\n";
          printPos(pos);
          return 0;
        }
      }
    }
    cout << "No solution.\n";
    return 0;
  }
  if (j1.first == -1 && j2.first == -1) {
    vector<pair<int, int>> pos = getSquares();
    if (pos[0].first == -1)
      cout << "No solution.\n";
    else {
      cout << "Solution exists.\n";
      cout << "There are no jokers.\n";
      printPos(pos);
    }
    return 0;
  }
  bool swaped = false;
  if (j1.first == -1) {
    swap(j1, j2);
    swaped = true;
  }
  if (j1.first != -1) {
    for (const auto &it : st) {
      mat[j1.first][j1.second] = it;
      vector<pair<int, int>> pos = getSquares();
      if (pos[0].first != -1) {
        cout << "Solution exists.\n";
        cout << "Replace J" << (swaped ? 2 : 1) << " with " << it << ".\n";
        printPos(pos);
        return 0;
      }
    }
    cout << "No solution.\n";
  }
  return 0;
}
