#include <bits/stdc++.h>
using namespace std;
string arr[18][18] = {};
unordered_set<string> st;
unordered_set<char> ch, nom;
int n, m;
string arr2[] = {"D", "S", "H", "C"},
       Arr[] = {"2", "3", "4", "5", "6", "7", "8",
                "9", "T", "J", "Q", "K", "A"};
inline bool ongrid(int i, int j, int k, int l) {
  for (int z = k; z < k + 3; ++z) {
    for (int t = l; t < l + 3; ++t)
      if (i == z && t == j) return false;
  }
  if (i >= 0 && i < n && j >= 0 && j < m) return true;
  return false;
}
inline bool check(int i, int j, int k, int l) {
  ch.clear();
  nom.clear();
  for (int z = i; z < i + 3; ++z) {
    for (int q = j; q < j + 3; ++q) {
      if (!ongrid(z, q, k, l)) return false;
      ch.insert(arr[z][q][1]);
      nom.insert(arr[z][q][0]);
    }
  }
  if (ch.size() > 1 && nom.size() != 9) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < 13; ++i) {
    for (int j = 0; j < 4; ++j) {
      string str = "";
      str += Arr[i];
      str += arr2[j];
      st.insert(str);
    }
  }
  int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (arr[i][j] == "J1")
        x1 = i, y1 = j;
      else if (arr[i][j] == "J2")
        x2 = i, y2 = j;
      st.erase(arr[i][j]);
    }
  }
  bool is = false;
  int ansx = -1, ansy = -1, ans2x = -1, ans2y = -1;
  string chx, chy;
  for (auto u : st) {
    for (auto z : st) {
      if (x1 != -1) {
        arr[x1][y1] = u;
      }
      if (x2 != -1) {
        if (z != u)
          arr[x2][y2] = z;
        else
          continue;
      }
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
          for (int k = 0; k < n; ++k) {
            for (int l = 0; l < m; ++l) {
              if (check(i, j, k, l) && check(k, l, i, j)) {
                is = true;
                chx = u;
                chy = z;
                ansx = i + 1, ansy = j + 1, ans2x = k + 1, ans2y = l + 1;
                if (is) break;
              }
            }
            if (is) break;
          }
          if (is) break;
        }
        if (is) break;
      }
      if (is) break;
    }
    if (is) break;
  }
  if (is) {
    cout << "Solution exists.\n";
    if (x1 != -1) {
      if (x2 != -1) {
        cout << "Replace J1 with " << chx << " and J2 with " << chy << ".\n";
      } else {
        cout << "Replace J1 with " << chx << ".\n";
      }
    } else if (x2 != -1) {
      cout << "Replace J2 with " << chy << ".\n";
    } else {
      cout << "There are no jokers.\n";
    }
    cout << "Put the first square to (" << ansx << ", " << ansy << ").\n";
    cout << "Put the second square to (" << ans2x << ", " << ans2y << ").\n";
  } else
    cout << "No solution.\n";
  return 0;
}
