Problem: Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them.

Vasya lays out nm cards as a rectangle n × m. If there are jokers among them, then Vasya should change them with some of the rest of 54 - nm cards (which are not layed out) so that there were no jokers left. Vasya can pick the cards to replace the jokers arbitrarily. Remember, that each card presents in pack exactly once (i. e. in a single copy). Vasya tries to perform the replacements so that the solitaire was solved.

Vasya thinks that the solitaire is solved if after the jokers are replaced, there exist two non-overlapping squares 3 × 3, inside each of which all the cards either have the same suit, or pairwise different ranks.

Determine by the initial position whether the solitaire can be solved or not. If it can be solved, show the way in which it is possible.

Input

The first line contains integers n and m (3 ≤ n, m ≤ 17, n × m ≤ 52). Next n lines contain m words each. Each word consists of two letters. The jokers are defined as "J1" and "J2" correspondingly. For the rest of the cards, the first letter stands for the rank and the second one — for the suit. The possible ranks are: "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" and "A". The possible suits are: "C", "D", "H" and "S". All the cards are different.

Output

If the Solitaire can be solved, print on the first line "Solution exists." without the quotes. On the second line print in what way the jokers can be replaced. Three variants are possible:

  * "There are no jokers.", if there are no jokers in the input data.
  * "Replace Jx with y.", if there is one joker. x is its number, and y is the card it should be replaced with.
  * "Replace J1 with x and J2 with y.", if both jokers are present in the input data. x and y here represent distinct cards with which one should replace the first and the second jokers correspondingly.



On the third line print the coordinates of the upper left corner of the first square 3 × 3 in the format "Put the first square to (r, c).", where r and c are the row and the column correspondingly. In the same manner print on the fourth line the coordinates of the second square 3 × 3 in the format "Put the second square to (r, c).".

If there are several solutions to that problem, print any of them.

If there are no solutions, print of the single line "No solution." without the quotes.

See the samples to understand the output format better.

Examples

Input

4 6
2S 3S 4S 7S 8S AS
5H 6H 7H 5S TC AC
8H 9H TH 7C 8C 9C
2D 2C 3C 4C 5C 6C


Output

No solution.

Input

4 6
2S 3S 4S 7S 8S AS
5H 6H 7H J1 TC AC
8H 9H TH 7C 8C 9C
2D 2C 3C 4C 5C 6C


Output

Solution exists.
Replace J1 with 2H.
Put the first square to (1, 1).
Put the second square to (2, 4).


Input

4 6
2S 3S 4S 7S 8S AS
5H 6H 7H QC TC AC
8H 9H TH 7C 8C 9C
2D 2C 3C 4C 5C 6C


Output

Solution exists.
There are no jokers.
Put the first square to (1, 1).
Put the second square to (2, 4).

Note

The pretests cover all the possible output formats.

Solution (in CPP):

Solution:
#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;
}