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 = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int n, m;
bool check_square(const vector<pair<int, int>> &have) {
  bool ok = 1;
  for (auto i : have)
    if (i.second != have[0].second) ok = 0;
  if (ok) return 1;
  vector<int> cnt(20);
  for (auto i : have) cnt[i.first]++;
  for (auto i : cnt)
    if (i > 1) return 0;
  return 1;
}
pair<pair<int, int>, pair<int, int>> get_squares(
    const vector<vector<pair<int, int>>> &g) {
  for (int x1 = 0; x1 < n - 2; ++x1) {
    for (int y1 = 0; y1 < m - 2; ++y1) {
      for (int x2 = 0; x2 < n - 2; ++x2) {
        for (int y2 = 0; y2 < m - 2; ++y2) {
          if (abs(x1 - x2) < 3 && abs(y1 - y2) < 3) continue;
          vector<pair<int, int>> h1, h2;
          for (int dx = 0; dx < 3; ++dx)
            for (int dy = 0; dy < 3; ++dy) {
              h1.push_back(g[x1 + dx][y1 + dy]);
              h2.push_back(g[x2 + dx][y2 + dy]);
            }
          if (check_square(h1) && check_square(h2)) return {{x1, y1}, {x2, y2}};
        }
      }
    }
  }
  return {{-1, -1}, {-1, -1}};
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> m;
  int cntj = 0;
  pair<int, int> jpos[2];
  string jstr[2];
  vector<vector<pair<int, int>>> g(n, vector<pair<int, int>>(m));
  vector<int> parsef(256, 16), parses(256, 16);
  for (int i = '2'; i <= '9'; ++i) parsef[i] = i - '2';
  parsef['T'] = 8;
  parsef['J'] = 9;
  parsef['Q'] = 10;
  parsef['K'] = 11;
  parsef['A'] = 12;
  parses['C'] = 0;
  parses['D'] = 1;
  parses['H'] = 2;
  parses['S'] = 3;
  vector<vector<bool>> used(20, vector<bool>(20));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      string s;
      cin >> s;
      if (s[1] == '1' || s[1] == '2') {
        jpos[cntj] = {i, j};
        jstr[cntj++] = s;
      } else {
        g[i][j] = {parsef[s[0]], parses[s[1]]};
        used[parsef[s[0]]][parses[s[1]]] = 1;
      }
    }
  vector<pair<int, int>> canchange;
  for (int i = 0; i < 13; ++i)
    for (int j = 0; j < 4; ++j)
      if (!used[i][j]) canchange.push_back({i, j});
  if (cntj == 0) {
    auto ans = get_squares(g);
    if (ans.first.first != -1) {
      cout << "Solution exists." << endl;
      cout << "There are no jokers." << endl;
      cout << "Put the first square to (" << ans.first.first + 1 << ", "
           << ans.first.second + 1 << ")." << endl;
      cout << "Put the second square to (" << ans.second.first + 1 << ", "
           << ans.second.second + 1 << ")." << endl;
      return 0;
    }
  } else if (cntj == 1) {
    for (auto changeto : canchange) {
      g[jpos[0].first][jpos[0].second] = changeto;
      auto ans = get_squares(g);
      if (ans.first.first != -1) {
        cout << "Solution exists." << endl;
        string parse = "##";
        for (int i = 0; i < 256; ++i) {
          if (parsef[i] == changeto.first) parse[0] = i;
          if (parses[i] == changeto.second) parse[1] = i;
        }
        cout << "Replace " << jstr[0] << " with " << parse << "." << endl;
        cout << "Put the first square to (" << ans.first.first + 1 << ", "
             << ans.first.second + 1 << ")." << endl;
        cout << "Put the second square to (" << ans.second.first + 1 << ", "
             << ans.second.second + 1 << ")." << endl;
        return 0;
      }
    }
  } else {
    for (int changef = 0; changef < canchange.size(); ++changef) {
      for (int changes = 0; changes < canchange.size(); ++changes) {
        if (changef == changes) continue;
        g[jpos[0].first][jpos[0].second] = canchange[changef];
        g[jpos[1].first][jpos[1].second] = canchange[changes];
        auto ans = get_squares(g);
        if (ans.first.first != -1) {
          cout << "Solution exists." << endl;
          string jf = "##", js = "##";
          for (int i = 0; i < 256; ++i) {
            if (parsef[i] == canchange[changef].first) jf[0] = i;
            if (parses[i] == canchange[changef].second) jf[1] = i;
            if (parsef[i] == canchange[changes].first) js[0] = i;
            if (parses[i] == canchange[changes].second) js[1] = i;
          }
          if (jstr[0] == "J2") swap(jf, js);
          cout << "Replace J1 with " << jf << " and J2 with " << js << "."
               << endl;
          cout << "Put the first square to (" << ans.first.first + 1 << ", "
               << ans.first.second + 1 << ")." << endl;
          cout << "Put the second square to (" << ans.second.first + 1 << ", "
               << ans.second.second + 1 << ")." << endl;
          return 0;
        }
      }
    }
  }
  cout << "No solution." << endl;
  return 0;
}