#include <bits/stdc++.h>
using namespace std;
string a = "23456789TJQKA", b = "CDHS12";
bool u[13][6], p = false, c[13];
int f[17][17][2], h[2][2], g[52][2], ans[2][2], n, m, ch[2][2];
bool found() {
  int t = 0;
  bool can;
  for (int i = 0; i < n - 2; i++)
    for (int j = 0; j < m - 2; j++) {
      can = true;
      for (int x = i; x < i + 3; x++)
        for (int y = j; y < j + 3; y++)
          if (f[x][y][1] != f[i][j][1]) {
            can = false;
            break;
          }
      if (!can) {
        can = true;
        memset(c, 0, sizeof(c));
        for (int x = i; x < i + 3; x++) {
          for (int y = j; y < j + 3; y++) {
            if (c[f[x][y][0]]) {
              can = false;
              break;
            } else
              c[f[x][y][0]] = true;
          }
          if (!can) break;
        }
      }
      if (can) {
        g[t][0] = i;
        g[t][1] = j;
        t++;
      }
    }
  if (t > 1)
    for (int i = 0; i < t - 1; i++)
      for (int j = i + 1; j < t; j++) {
        if ((abs(g[i][0] - g[j][0]) > 2) || (abs(g[i][1] - g[j][1]) > 2)) {
          ans[0][0] = g[i][0];
          ans[0][1] = g[i][1];
          ans[1][0] = g[j][0];
          ans[1][1] = g[j][1];
          return true;
        }
      }
  return false;
}
void work(int x) {
  if (x == 6) {
    p = found();
    if (p) {
      printf("Solution exists.\n");
      bool q = true;
      for (int i = 4; i < 6; i++)
        if (u[9][i]) {
          if (q) {
            printf("Replace ");
            q = false;
          } else
            printf(" and ");
          cout << 'J' << b[i] << " with " << a[ch[i - 4][0]] << b[ch[i - 4][1]];
        }
      if (q) printf("There are no jokers");
      printf(".\n");
      printf("Put the first square to (%d, %d).\n", ans[0][0] + 1,
             ans[0][1] + 1);
      printf("Put the second square to (%d, %d).\n", ans[1][0] + 1,
             ans[1][1] + 1);
    }
  } else if (u[9][x]) {
    for (int i = 0; i < 13; i++)
      for (int j = 0; j < 4; j++)
        if (!u[i][j]) {
          u[i][j] = true;
          ch[x - 4][0] = i;
          ch[x - 4][1] = j;
          f[h[x - 4][0]][h[x - 4][1]][0] = i;
          f[h[x - 4][0]][h[x - 4][1]][1] = j;
          work(x + 1);
          if (p)
            return;
          else
            u[i][j] = false;
        }
  } else
    work(x + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char z;
      cin >> z;
      for (int k = 0; k < 13; k++)
        if (a[k] == z) {
          f[i][j][0] = k;
          break;
        }
      cin >> z;
      for (int k = 0; k < 6; k++)
        if (b[k] == z) {
          f[i][j][1] = k;
          break;
        }
      u[f[i][j][0]][f[i][j][1]] = true;
      if (f[i][j][1] > 3) {
        h[f[i][j][1] - 4][0] = i;
        h[f[i][j][1] - 4][1] = j;
      }
    }
  work(4);
  if (!p) printf("No solution.\n");
  return 0;
}
