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 n, m;
int esta[140];
string suit = "CDHS";
int tab[20][20];
vector<pair<int, int> > J;
int encode(string s) {
  char c = s[s.size() - 1];
  s = s.substr(0, s.size() - 1);
  int nat;
  if (s[0] == 'J' && suit.find(c) == -1) return '0' - c;
  if (s[0] == 'T')
    nat = 10;
  else if (s[0] == 'J')
    nat = 11;
  else if (s[0] == 'Q')
    nat = 12;
  else if (s[0] == 'K')
    nat = 13;
  else if (s[0] == 'A')
    nat = 1;
  else {
    istringstream is(s);
    is >> nat;
  }
  return nat * 10 + suit.find(c);
}
bool inter(int a, int b, int i, int j) {
  int dx = abs(a - i);
  int dy = abs(b - j);
  if (dx < 3 and dy < 3) return 1;
  return 0;
}
bool solute(int i1, int j1) {
  int bien = true;
  for (int i = (int)i1; i < (int)i1 + 3; i++) {
    for (int j = (int)j1; j < (int)j1 + 3; j++) {
      if (tab[i][j] != tab[i1][j1]) {
        bien = false;
        goto fin;
      }
    }
  }
  if (bien) return 1;
fin:
  for (int i = (int)i1; i < (int)i1 + 3; i++) {
    for (int j = (int)j1; j < (int)j1 + 3; j++) {
      for (int a = (int)i1; a < (int)i1 + 3; a++) {
        for (int b = (int)j1; b < (int)j1 + 3; b++) {
          if (a == i && b == j) continue;
          if (tab[i][j] / 10 == tab[a][b] / 10) return 0;
        }
      }
    }
  }
  return 1;
}
vector<pair<int, int> > solve() {
  vector<pair<int, int> > ans;
  for (int i1 = (int)0; i1 < (int)n - 2; i1++) {
    for (int j1 = (int)0; j1 < (int)m - 2; j1++) {
      for (int i2 = (int)0; i2 < (int)n - 2; i2++) {
        for (int j2 = (int)0; j2 < (int)m - 2; j2++) {
          if (inter(i1, j1, i2, j2)) continue;
          if (solute(i1, j1) && solute(i2, j2)) {
            ans.push_back(pair<int, int>(i1, j1));
            ans.push_back(pair<int, int>(i2, j2));
            return ans;
          }
        }
      }
    }
  }
  return ans;
}
int valid(int i) {
  char c = i % 10;
  int rank = i / 10;
  if (rank > 13 || rank <= 0) return 0;
  if (c > 3 || c < 0) return 0;
  return 1;
}
int decode(int a) {
  char c = suit[a % 10];
  int peso = a / 10;
  if (peso == 1)
    cout << "A";
  else if (peso >= 10) {
    string tmp = "TJQK";
    cout << tmp[peso - 10];
  } else {
    cout << peso;
  }
  cout << c;
  return 1;
}
int main() {
  vector<int> ides;
  cin >> n >> m;
  memset(esta, 0, sizeof(esta));
  for (int i = (int)0; i < (int)n; i++)
    for (int j = (int)0; j < (int)m; j++) {
      string str;
      cin >> str;
      int tmp = encode(str);
      if (tmp < 0) {
        J.push_back(pair<int, int>(i, j));
        ides.push_back(-tmp);
      } else
        esta[tmp] = 1;
      tab[i][j] = tmp;
    }
  vector<pair<int, int> > ans;
  if (J.empty()) {
    ans = solve();
    if (ans.empty())
      cout << "No solution." << endl;
    else {
      cout << "Solution exists." << endl;
      cout << "There are no jokers." << endl;
    }
  } else {
    if (J.size() == 1) {
      for (int i = (int)0; i < (int)140; i++) {
        if (valid(i) && esta[i] == 0) {
          tab[J[0].first][J[0].second] = i;
          ans = solve();
          if (!ans.empty()) break;
        }
      }
    } else {
      int i1 = J[0].first, i2 = J[1].first;
      int j1 = J[0].second, j2 = J[1].second;
      for (int i = (int)0; i < (int)140; i++) {
        if (!valid(i)) continue;
        if (esta[i]) continue;
        for (int j = (int)0; j < (int)140; j++) {
          if (esta[j]) continue;
          if (!valid(j)) continue;
          if (i == j) continue;
          tab[i1][j1] = i;
          tab[i2][j2] = j;
          ans = solve();
          if (!ans.empty()) break;
        }
        if (!ans.empty()) break;
      }
    }
    if (ans.empty())
      cout << "No solution." << endl;
    else
      cout << "Solution exists." << endl;
  }
  if (!ans.empty()) {
    if (J.size() == 2)
      if (ides[0] > ides[1]) {
        swap(J[0], J[1]);
        swap(ides[0], ides[1]);
      }
    if (!J.empty()) {
      for (int i = (int)0; i < (int)1; i++) {
        int a = J[i].first;
        int b = J[i].second;
        printf("Replace J%d with ", ides[0]);
        decode(tab[a][b]);
      }
      if (J.size() == 2) {
        printf(" and J2 with ");
        decode(tab[J[1].first][J[1].second]);
      }
    }
    if (!J.empty()) cout << "." << endl;
    printf("Put the first square to (%d, %d).\n", ans[0].first + 1,
           ans[0].second + 1);
    printf("Put the second square to (%d, %d).\n", ans[1].first + 1,
           ans[1].second + 1);
  }
  return 0;
}