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;
template <class T>
string i2s(T x) {
  ostringstream o;
  o << x;
  return o.str();
}
int n, m;
int mat[20][20];
bool used[60];
vector<int> remain;
pair<char, char> getRank(int d) {
  char c1, c2;
  int d1 = d % 13 + 1;
  if (d1 == 10)
    c1 = 'T';
  else if (d1 == 11)
    c1 = 'J';
  else if (d1 == 12)
    c1 = 'Q';
  else if (d1 == 13)
    c1 = 'K';
  else if (d1 == 1)
    c1 = 'A';
  else
    c1 = '0' + d1;
  int d2 = d / 13;
  if (d2 == 0)
    c2 = 'C';
  else if (d2 == 1)
    c2 = 'D';
  else if (d2 == 2)
    c2 = 'H';
  else
    c2 = 'S';
  return make_pair(c1, c2);
}
int getIndex(char c1, char c2) {
  int d1, d2;
  if (c1 == 'T')
    d1 = 10;
  else if (c1 == 'J')
    d1 = 11;
  else if (c1 == 'Q')
    d1 = 12;
  else if (c1 == 'K')
    d1 = 13;
  else if (c1 == 'A')
    d1 = 1;
  else
    d1 = c1 - '0';
  if (c2 == 'C')
    d2 = 0;
  else if (c2 == 'D')
    d2 = 13;
  else if (c2 == 'H')
    d2 = 26;
  else
    d2 = 39;
  return d1 + d2 - 1;
}
bool check3(pair<int, int> p1, pair<int, int> p2) {
  return p2.first >= p1.first + 3 || p2.second >= p1.second + 3;
}
bool check2(vector<int>& v) {
  int num[14] = {0};
  for (int i = 0; i < v.size(); ++i) num[v[i] % 13]++;
  bool ok = true;
  for (int i = 0; i < 13; ++i) {
    if (num[i] > 1) {
      ok = false;
      break;
    }
  }
  if (ok) return true;
  ok = true;
  for (int i = 1; i < v.size(); ++i) {
    if (v[i] / 13 != v[0] / 13) {
      ok = false;
      break;
    }
  }
  if (ok) return true;
  return false;
}
bool check1(pair<pair<int, int>, pair<int, int> >& ret) {
  vector<pair<int, int> > good;
  for (int i = 0; i <= n - 3; ++i) {
    for (int j = 0; j <= m - 3; ++j) {
      vector<int> v;
      for (int di = 0; di < 3; ++di) {
        for (int dj = 0; dj < 3; ++dj) {
          v.push_back(mat[i + di][j + dj]);
        }
      }
      if (check2(v)) good.push_back(make_pair(i, j));
    }
  }
  int sz = good.size();
  for (int i = 0; i < sz; ++i) {
    for (int j = i + 1; j < sz; ++j) {
      if (check3(good[i], good[j])) {
        ret = make_pair(good[i], good[j]);
        return true;
      }
    }
  }
  return false;
}
int main() {
  char buf[5];
  int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
  memset(used, 0, sizeof(used));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%s", buf);
      if (buf[0] == 'J' && buf[1] == '1') {
        x1 = i, y1 = j;
      } else if (buf[0] == 'J' && buf[1] == '2') {
        x2 = i, y2 = j;
      } else {
        mat[i][j] = getIndex(buf[0], buf[1]);
        used[mat[i][j]] = true;
      }
    }
  }
  for (int i = 0; i < 52; ++i)
    if (!used[i]) remain.push_back(i);
  pair<pair<int, int>, pair<int, int> > ans;
  if (x1 == -1 && x2 == -1) {
    if (check1(ans)) {
      printf("Solution exists.\nThere are no jokers.\n");
      printf("Put the first square to (%d, %d).\n", ans.first.first + 1,
             ans.first.second + 1);
      printf("Put the second square to (%d, %d).\n", ans.second.first + 1,
             ans.second.second + 1);
    } else {
      printf("No solution.\n");
    }
  } else if (x1 == -1 && x2 != -1) {
    bool flag = false;
    for (int i = 0; i < remain.size(); ++i) {
      mat[x2][y2] = remain[i];
      if (check1(ans)) {
        printf("Solution exists.\n");
        pair<char, char> pc = getRank(remain[i]);
        printf("Replace J2 with %c%c.\n", pc.first, pc.second);
        printf("Put the first square to (%d, %d).\n", ans.first.first + 1,
               ans.first.second + 1);
        printf("Put the second square to (%d, %d).\n", ans.second.first + 1,
               ans.second.second + 1);
        flag = true;
        break;
      }
    }
    if (!flag) printf("No solution.\n");
  } else if (x1 != -1 && x2 == -1) {
    bool flag = false;
    for (int i = 0; i < remain.size(); ++i) {
      mat[x1][y1] = remain[i];
      if (check1(ans)) {
        printf("Solution exists.\n");
        pair<char, char> pc = getRank(remain[i]);
        printf("Replace J1 with %c%c.\n", pc.first, pc.second);
        printf("Put the first square to (%d, %d).\n", ans.first.first + 1,
               ans.first.second + 1);
        printf("Put the second square to (%d, %d).\n", ans.second.first + 1,
               ans.second.second + 1);
        flag = true;
        break;
      }
    }
    if (!flag) printf("No solution.\n");
  } else {
    bool flag = false;
    for (int i = 0; i < remain.size(); ++i) {
      for (int j = 0; j < remain.size(); ++j)
        if (i != j) {
          mat[x1][y1] = remain[i];
          mat[x2][y2] = remain[j];
          if (check1(ans)) {
            printf("Solution exists.\n");
            pair<char, char> pc1 = getRank(remain[i]);
            pair<char, char> pc2 = getRank(remain[j]);
            printf("Replace J1 with %c%c and J2 with %c%c.\n", pc1.first,
                   pc1.second, pc2.first, pc2.second);
            printf("Put the first square to (%d, %d).\n", ans.first.first + 1,
                   ans.first.second + 1);
            printf("Put the second square to (%d, %d).\n", ans.second.first + 1,
                   ans.second.second + 1);
            flag = true;
            break;
          }
        }
      if (flag) break;
    }
    if (!flag) printf("No solution.\n");
  }
  return 0;
}