#include <bits/stdc++.h>
using namespace std;
int abs(int a) { return max(a, -a); }
int n, m, used[4][14] = {0}, card[17][17][2], Joker_num = 0,
          Joker_pos[2][2] = {-1, -1, -1, -1}, rcard[54][2], rc = 0, sp[2][2];
char mymap[17][17][3];
bool check() {
  int square = 0;
  for (int i = 0; i <= n - 3; i++) {
    for (int j = 0; j <= m - 3; j++) {
      if (square >= 2) return true;
      if (square == 1) {
        if (abs(sp[0][0] - i - 1) <= 2 && abs(sp[0][1] - j - 1) <= 2) continue;
      }
      int a = card[i][j][0], flag1 = 1;
      for (int x = i; x <= i + 2; x++) {
        for (int y = j; y <= j + 2; y++) {
          if (card[x][y][0] != a) flag1 = 0;
        }
      }
      if (flag1) {
        square++;
        sp[square - 1][0] = i + 1;
        sp[square - 1][1] = j + 1;
        continue;
      }
      int visited[14], flag2 = 1;
      memset(visited, 0, sizeof(visited));
      for (int x = i; x <= i + 2; x++) {
        for (int y = j; y <= j + 2; y++) {
          visited[card[x][y][1]]++;
          if (visited[card[x][y][1]] > 1) flag2 = 0;
        }
      }
      if (flag2) {
        square++;
        sp[square - 1][0] = i + 1;
        sp[square - 1][1] = j + 1;
      }
    }
  }
  if (square >= 2)
    return true;
  else
    return false;
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%s", mymap[i][j]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mymap[i][j][0] == 'J' &&
          (mymap[i][j][1] == '1' || mymap[i][j][1] == '2')) {
        Joker_pos[Joker_num][0] = i;
        Joker_pos[Joker_num][1] = j;
        card[i][j][0] = 4;
        card[i][j][1] = mymap[i][j][1] - '0';
        Joker_num++;
        if (mymap[i][j][1] == '1' && Joker_num == 2)
          swap(Joker_pos[0], Joker_pos[1]);
        continue;
      }
      if (mymap[i][j][1] == 'C') card[i][j][0] = 0;
      if (mymap[i][j][1] == 'D') card[i][j][0] = 1;
      if (mymap[i][j][1] == 'H') card[i][j][0] = 2;
      if (mymap[i][j][1] == 'S') card[i][j][0] = 3;
      if (mymap[i][j][0] == 'T') {
        card[i][j][1] = 10;
      } else if (mymap[i][j][0] == 'J') {
        card[i][j][1] = 11;
      } else if (mymap[i][j][0] == 'Q') {
        card[i][j][1] = 12;
      } else if (mymap[i][j][0] == 'K') {
        card[i][j][1] = 13;
      } else if (mymap[i][j][0] == 'A') {
        card[i][j][1] = 1;
      } else
        card[i][j][1] = mymap[i][j][0] - '0';
      used[card[i][j][0]][card[i][j][1]] = 1;
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j <= 13; j++) {
      if (used[i][j]) continue;
      rcard[rc][0] = i;
      rcard[rc][1] = j;
      rc++;
    }
  }
  if (Joker_num == 0) {
    memset(sp, 0, sizeof(sp));
    if (check()) {
      printf(
          "Solution exists.\nThere are no jokers.\nPut the first square to "
          "(%d, %d).\nPut the second square to (%d, %d).",
          sp[0][0], sp[0][1], sp[1][0], sp[1][1]);
      return 0;
    }
  } else if (Joker_num == 1) {
    int x = Joker_pos[0][0], y = Joker_pos[0][1];
    int tmp = card[x][y][1];
    for (int i = 0; i < rc; i++) {
      memset(sp, 0, sizeof(sp));
      card[x][y][1] = rcard[i][1];
      card[x][y][0] = rcard[i][0];
      if (check()) {
        char a, b;
        if (rcard[i][1] == 10)
          a = 'T';
        else if (rcard[i][1] == 11)
          a = 'J';
        else if (rcard[i][1] == 12)
          a = 'Q';
        else if (rcard[i][1] == 13)
          a = 'K';
        else if (rcard[i][1] == 1)
          a = 'A';
        else
          a = rcard[i][1] + '0';
        if (rcard[i][0] == 0)
          b = 'C';
        else if (rcard[i][0] == 1)
          b = 'D';
        else if (rcard[i][0] == 2)
          b = 'H';
        else if (rcard[i][0] == 3)
          b = 'S';
        if (tmp == 1)
          printf(
              "Solution exists.\nReplace J1 with %c%c.\nPut the first square "
              "to (%d, %d).\nPut the second square to (%d, %d).",
              a, b, sp[0][0], sp[0][1], sp[1][0], sp[1][1]);
        else
          printf(
              "Solution exists.\nReplace J2 with %c%c.\nPut the first square "
              "to (%d, %d).\nPut the second square to (%d, %d).",
              a, b, sp[0][0], sp[0][1], sp[1][0], sp[1][1]);
        return 0;
      }
    }
  } else if (Joker_num == 2) {
    int x1 = Joker_pos[0][0], y1 = Joker_pos[0][1], x2 = Joker_pos[1][0],
        y2 = Joker_pos[1][1];
    for (int i = 0; i < rc; i++) {
      for (int j = 0; j < rc; j++) {
        if (i == j) continue;
        memset(sp, 0, sizeof(sp));
        card[x1][y1][1] = rcard[i][1];
        card[x1][y1][0] = rcard[i][0];
        card[x2][y2][1] = rcard[j][1];
        card[x2][y2][0] = rcard[j][0];
        if (check()) {
          char a, b, c, d;
          if (rcard[i][1] == 10)
            a = 'T';
          else if (rcard[i][1] == 11)
            a = 'J';
          else if (rcard[i][1] == 12)
            a = 'Q';
          else if (rcard[i][1] == 13)
            a = 'K';
          else if (rcard[i][1] == 1)
            a = 'A';
          else
            a = rcard[i][1] + '0';
          if (rcard[i][0] == 0)
            b = 'C';
          else if (rcard[i][0] == 1)
            b = 'D';
          else if (rcard[i][0] == 2)
            b = 'H';
          else if (rcard[i][0] == 3)
            b = 'S';
          if (rcard[j][1] == 10)
            c = 'T';
          else if (rcard[j][1] == 11)
            c = 'J';
          else if (rcard[j][1] == 12)
            c = 'Q';
          else if (rcard[j][1] == 13)
            c = 'K';
          else if (rcard[j][1] == 1)
            c = 'A';
          else
            c = rcard[j][1] + '0';
          if (rcard[j][0] == 0)
            d = 'C';
          else if (rcard[j][0] == 1)
            d = 'D';
          else if (rcard[j][0] == 2)
            d = 'H';
          else if (rcard[j][0] == 3)
            d = 'S';
          printf(
              "Solution exists.\nReplace J1 with %c%c and J2 with %c%c.\nPut "
              "the first square to (%d, %d).\nPut the second square to (%d, "
              "%d).",
              a, b, c, d, sp[0][0], sp[0][1], sp[1][0], sp[1][1]);
          return 0;
        }
      }
    }
  }
  printf("No solution.");
  return 0;
}
