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;
const int INF = 2e9;
const long long LINF = 2e16;
const int magic = 348;
const int MOD = 998244353;
const double eps = 1e-10;
const double pi = acos(-1);
inline int getint() {
  bool f;
  char ch;
  int res;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
inline char Getchar() {
  bool f;
  char ch;
  while (!(isalpha(ch = getchar()) || isdigit(ch))) {
  }
  return ch;
}
bool exist[148];
int n, m;
int table[148], ntable[48], stable[48];
struct node {
  char num, suit;
  node() {}
  inline node(char nu, char su) {
    num = nu;
    suit = su;
  }
  inline void input() {
    num = Getchar();
    suit = Getchar();
  }
  inline void print() { cout << num << suit; }
} a[20][20];
inline int getind(node cur) {
  return (table[cur.suit] - 1) * 13 + table[cur.num];
}
inline node getcard(int ind) {
  int su = (ind - 1) / 13 + 1, nu = ind - (su - 1) * 13;
  return node(ntable[nu], stable[su]);
}
inline void init_table() {
  table['A'] = 1;
  for (register int i = 2; i <= 9; i++) table['0' + i] = i;
  table['T'] = 10;
  table['J'] = 11;
  table['Q'] = 12;
  table['K'] = 13;
  table['C'] = 1;
  table['D'] = 2;
  table['H'] = 3;
  table['S'] = 4;
  ntable[1] = 'A';
  for (register int i = 2; i <= 9; i++) ntable[i] = '0' + i;
  ntable[10] = 'T';
  ntable[11] = 'J';
  ntable[12] = 'Q';
  ntable[13] = 'K';
  stable[1] = 'C';
  stable[2] = 'D';
  stable[3] = 'H';
  stable[4] = 'S';
}
pair<int, int> jpos[5];
int cnt;
int type[5];
pair<int, int> b[148];
int tot;
inline bool check(int sx, int sy) {
  int i, j;
  bool f = true;
  for (i = sx; i <= sx + 2; i++) {
    for (j = sy; j <= sy + 2; j++)
      if (a[i][j].suit != a[sx][sy].suit) {
        f = false;
        break;
      }
    if (!f) break;
  }
  if (f) return true;
  int vs[14];
  memset(vs, 0, sizeof(vs));
  for (i = sx; i <= sx + 2; i++)
    for (j = sy; j <= sy + 2; j++) vs[table[a[i][j].num]]++;
  for (i = 1; i <= 13; i++)
    if (vs[i] > 1) return false;
  return true;
}
inline bool overlapping(pair<int, int> pt1, pair<int, int> pt2) {
  if (pt1.first - 2 <= pt2.first && pt2.first <= pt1.first + 2 &&
      pt1.second - 2 <= pt2.second && pt2.second <= pt1.second + 2)
    return true;
  return false;
}
int main() {
  init_table();
  int i, j;
  n = getint();
  m = getint();
  cnt = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      a[i][j].input();
      if (isdigit(a[i][j].suit))
        jpos[++cnt] = make_pair(i, j), type[cnt] = a[i][j].suit - '0';
      else
        exist[getind(a[i][j])] = true;
    }
  if (cnt == 2 && a[jpos[1].first][jpos[1].second].suit == '2')
    swap(jpos[1], jpos[2]);
  if (!cnt) {
    for (i = 1; i <= n - 2; i++)
      for (j = 1; j <= m - 2; j++)
        if (check(i, j)) b[++tot] = make_pair(i, j);
    int ans1 = 0, ans2 = 0;
    for (i = 1; i <= tot - 1; i++) {
      for (j = i + 1; j <= tot; j++)
        if (!overlapping(b[i], b[j])) {
          ans1 = i;
          ans2 = j;
          break;
        }
      if (ans1) break;
    }
    if (!ans1)
      puts("No solution.");
    else {
      puts("Solution exists.");
      puts("There are no jokers.");
      printf("Put the first square to (%d, %d).\n", b[ans1].first,
             b[ans1].second);
      printf("Put the second square to (%d, %d).\n", b[ans2].first,
             b[ans2].second);
    }
    return 0;
  }
  if (cnt == 1) {
    for (register int r = 1; r <= 52; r++)
      if (!exist[r]) {
        a[jpos[1].first][jpos[1].second] = getcard(r);
        tot = 0;
        for (i = 1; i <= n - 2; i++)
          for (j = 1; j <= m - 2; j++)
            if (check(i, j)) b[++tot] = make_pair(i, j);
        int ans1 = 0, ans2 = 0;
        for (i = 1; i <= tot - 1; i++) {
          for (j = i + 1; j <= tot; j++)
            if (!overlapping(b[i], b[j])) {
              ans1 = i;
              ans2 = j;
              break;
            }
          if (ans1) break;
        }
        if (!ans1)
          continue;
        else {
          puts("Solution exists.");
          printf("Replace J%d with ", type[1]);
          getcard(r).print();
          puts(".");
          printf("Put the first square to (%d, %d).\n", b[ans1].first,
                 b[ans1].second);
          printf("Put the second square to (%d, %d).\n", b[ans2].first,
                 b[ans2].second);
          return 0;
        }
      }
    puts("No solution.");
    return 0;
  }
  for (register int r1 = 1; r1 <= 52; r1++)
    if (!exist[r1])
      for (register int r2 = 1; r2 <= 52; r2++)
        if (r1 != r2 && !exist[r2]) {
          a[jpos[1].first][jpos[1].second] = getcard(r1);
          a[jpos[2].first][jpos[2].second] = getcard(r2);
          tot = 0;
          for (i = 1; i <= n - 2; i++)
            for (j = 1; j <= m - 2; j++)
              if (check(i, j)) b[++tot] = make_pair(i, j);
          int ans1 = 0, ans2 = 0;
          for (i = 1; i <= tot - 1; i++) {
            for (j = i + 1; j <= tot; j++)
              if (!overlapping(b[i], b[j])) {
                ans1 = i;
                ans2 = j;
                break;
              }
            if (ans1) break;
          }
          if (!ans1)
            continue;
          else {
            puts("Solution exists.");
            printf("Replace J1 with ");
            getcard(r1).print();
            printf(" and J2 with ");
            getcard(r2).print();
            puts(".");
            printf("Put the first square to (%d, %d).\n", b[ans1].first,
                   b[ans1].second);
            printf("Put the second square to (%d, %d).\n", b[ans2].first,
                   b[ans2].second);
            return 0;
          }
        }
  puts("No solution.");
  return 0;
}