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>
typedef struct {
  int num;
  int suit;
} card;
typedef struct {
  int x, y;
} point;
card a[20][20];
char str[20];
int vis[20][5];
point jok[2];
char suithash[4] = {'C', 'D', 'H', 'S'};
char numhash[4] = {'T', 'J', 'Q', 'K'};
point ret1, ret2;
int n, m;
int hash[15];
point res1[100];
point res2[100];
int abs(int t) { return t > 0 ? t : -t; }
char Change(int t) {
  char ret;
  if (t <= 9 && t > 1)
    ret = t + '0';
  else if (t == 1)
    ret = 'A';
  else
    ret = numhash[t - 10];
  return ret;
}
int ChangeSuit(char t) {
  char ret;
  if (t == 'C')
    ret = 0;
  else if (t == 'D')
    ret = 1;
  else if (t == 'H')
    ret = 2;
  else
    ret = 3;
  return ret;
}
int ChangeNum(char t) {
  char ret;
  if (t >= '2' && t <= '9')
    ret = t - '0';
  else if (t == 'A')
    ret = 1;
  else if (t == 'T')
    ret = 10;
  else if (t == 'J')
    ret = 11;
  else if (t == 'Q')
    ret = 12;
  else
    ret = 13;
  return ret;
}
bool Check1(int x, int y) {
  int i, j, s;
  s = 0;
  memset(hash, 0, sizeof(hash));
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      hash[a[x + i][y + j].suit] = 1;
    }
  }
  for (i = 0; i < 4; i++) {
    s += hash[i];
  }
  if (s == 1) return true;
  return false;
}
bool Check2(int x, int y) {
  int i, j, s;
  memset(hash, 0, sizeof(hash));
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      hash[a[x + i][y + j].num] = 1;
    }
  }
  s = 0;
  for (i = 0; i < 14; i++) {
    s += hash[i];
  }
  if (s == 9) return true;
  return false;
}
bool Check() {
  int i, j, up1, up2;
  up1 = up2 = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (i + 3 > n || j + 3 > m) continue;
      if (Check1(i, j) == true) {
        res1[up1].x = i;
        res1[up1++].y = j;
      }
      if (Check2(i, j) == true) {
        res2[up2].x = i;
        res2[up2++].y = j;
      }
    }
  }
  for (i = 0; i < up1; i++) {
    for (j = i + 1; j < up1; j++) {
      if (abs(res1[i].x - res1[j].x) >= 3 || abs(res1[i].y - res1[j].y) >= 3) {
        ret1 = res1[i];
        ret2 = res1[j];
        return true;
      }
    }
  }
  for (i = 0; i < up2; i++) {
    for (j = i + 1; j < up2; j++) {
      if (abs(res2[i].x - res2[j].x) >= 3 || abs(res2[i].y - res2[j].y) >= 3) {
        ret1 = res2[i];
        ret2 = res2[j];
        return true;
      }
    }
  }
  return false;
}
int main() {
  int i, j, up, t, t1, k, l;
  char s1, s;
  card tag, tag1, tagg;
  scanf("%d%d", &n, &m);
  up = 0;
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%s", str);
      if (strcmp(str, "J1") == 0 || strcmp(str, "J2") == 0) {
        jok[up].x = i;
        jok[up].y = j;
        a[i][j].num = str[1] - '0';
        up++;
        continue;
      }
      a[i][j].suit = ChangeSuit(str[1]);
      a[i][j].num = ChangeNum(str[0]);
      vis[a[i][j].num][a[i][j].suit] = 1;
    }
  }
  if (up == 1) {
    tag = a[jok[0].x][jok[0].y];
    for (j = 1; j <= 13; j++) {
      for (k = 0; k < 4; k++) {
        if (vis[j][k] == false) {
          a[jok[0].x][jok[0].y].num = j;
          a[jok[0].x][jok[0].y].suit = k;
          if (Check() == true) {
            printf("Solution exists.\n");
            t = Change(j);
            printf("Replace J%d with %c%c.\n", tag.num, t, suithash[k]);
            printf("Put the first square to (%d, %d).\n", ret1.x + 1,
                   ret1.y + 1);
            printf("Put the second square to (%d, %d).\n", ret2.x + 1,
                   ret2.y + 1);
            return 0;
          }
        }
      }
    }
  } else if (up == 2) {
    tag = a[jok[0].x][jok[0].y];
    tag1 = a[jok[1].x][jok[1].y];
    for (i = 1; i <= 13; i++) {
      for (j = 0; j < 4; j++) {
        for (k = 1; k <= 13; k++) {
          for (l = 0; l < 4; l++) {
            if (vis[i][j] == true || vis[k][l] == true || (i == k && j == l))
              continue;
            a[jok[0].x][jok[0].y].num = i;
            a[jok[0].x][jok[0].y].suit = j;
            a[jok[1].x][jok[1].y].num = k;
            a[jok[1].x][jok[1].y].suit = l;
            if (Check() == true) {
              printf("Solution exists.\n");
              if (tag.num == 1) {
                t = Change(i);
                s = suithash[j];
                t1 = Change(k);
                s1 = suithash[l];
              } else {
                t1 = Change(i);
                s1 = suithash[j];
                t = Change(k);
                s = suithash[l];
              }
              printf("Replace J1 with %c%c and J2 with %c%c.\n", t, s, t1, s1);
              printf("Put the first square to (%d, %d).\n", ret1.x + 1,
                     ret1.y + 1);
              printf("Put the second square to (%d, %d).\n", ret2.x + 1,
                     ret2.y + 1);
              return 0;
            }
          }
        }
      }
    }
  } else {
    if (Check() == true) {
      printf("Solution exists.\n");
      printf("There are no jokers.\n");
      printf("Put the first square to (%d, %d).\n", ret1.x + 1, ret1.y + 1);
      printf("Put the second square to (%d, %d).\n", ret2.x + 1, ret2.y + 1);
      return 0;
    }
  }
  printf("No solution.\n");
  return 0;
}