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 char dcol[] = {'C', 'D', 'H', 'S'},
           dnum[] = {'2', '3', '4', '5', '6', '7', '8',
                     '9', 'T', 'J', 'Q', 'K', 'A'};
const int maxn = 20;
struct cards {
  char col, num;
} a[maxn][maxn];
int n, m, jnum, sing;
int jx[5], jy[5];
map<string, bool> vis;
bool check1(cards x, cards y) { return (x.col == y.col || x.num != y.num); }
bool check2(int i1, int j1, int i2, int j2) {
  return (abs(i1 - i2) >= 3 || abs(j1 - j2) >= 3);
}
inline string ctos(cards x) {
  string t;
  t = t + x.col + x.num;
  return t;
}
pair<pair<int, int>, pair<int, int> > check() {
  vector<pair<int, int> > ans;
  ans.clear();
  for (int si = 1; si <= n - 3 + 1; si++) {
    for (int sj = 1; sj <= m - 3 + 1; sj++) {
      int ei = si + 3 - 1, ej = sj + 3 - 1;
      vector<cards> t;
      t.clear();
      for (int i = si; i <= ei; i++) {
        for (int j = sj; j <= ej; j++) {
          t.push_back(a[i][j]);
        }
      }
      bool flag = 1;
      for (int i = 0; i < t.size(); i++) {
        for (int j = i + 1; j < t.size(); j++) {
          if (!check1(t[i], t[j])) {
            flag = 0;
            break;
          }
        }
        if (!flag) break;
      }
      if (flag) {
        ans.push_back(make_pair(si, sj));
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    for (int j = i + 1; j < ans.size(); j++) {
      if (check2(ans[i].first, ans[i].second, ans[j].first, ans[j].second))
        return make_pair(ans[i], ans[j]);
    }
  }
  return make_pair(make_pair(-1, -1), make_pair(-1, -1));
}
void outp(pair<int, int> x) {
  cout << "(" << x.first << ", " << x.second << ")." << endl;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      string t;
      cin >> t;
      a[i][j].col = t[1];
      a[i][j].num = t[0];
      if (a[i][j].col == '1' || a[i][j].col == '2') {
        jx[a[i][j].col - '0'] = i;
        jy[a[i][j].col - '0'] = j;
        jnum++;
        sing = a[i][j].col - '0';
      } else
        vis[ctos(a[i][j])] = 1;
    }
  }
  if (!jnum) {
    pair<pair<int, int>, pair<int, int> > ans = check();
    if (ans.first.first == -1) {
      cout << "No solution." << endl;
      return 0;
    } else {
      cout << "Solution exists." << endl << "There are no jokers." << endl;
      cout << "Put the first square to ";
      outp(ans.first);
      cout << "Put the second square to ";
      outp(ans.second);
      return 0;
    }
  }
  if (jnum == 1) {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 13; j++) {
        cards t;
        t.col = dcol[i];
        t.num = dnum[j];
        if (vis[ctos(t)]) continue;
        a[jx[sing]][jy[sing]] = t;
        pair<pair<int, int>, pair<int, int> > ans = check();
        if (ans.first.first != -1) {
          cout << "Solution exists." << endl;
          cout << "Replace J" << sing << " with " << t.num << t.col << "."
               << endl;
          cout << "Put the first square to ";
          outp(ans.first);
          cout << "Put the second square to ";
          outp(ans.second);
          return 0;
        }
      }
    }
    cout << "No solution." << endl;
    return 0;
  }
  if (jnum == 2) {
    for (int i1 = 0; i1 < 4; i1++) {
      for (int j1 = 0; j1 < 13; j1++) {
        cards t1;
        t1.col = dcol[i1];
        t1.num = dnum[j1];
        if (vis[ctos(t1)]) continue;
        vis[ctos(t1)] = 1;
        a[jx[1]][jy[1]] = t1;
        for (int i2 = 0; i2 < 4; i2++) {
          for (int j2 = 0; j2 < 13; j2++) {
            cards t2;
            t2.col = dcol[i2];
            t2.num = dnum[j2];
            if (vis[ctos(t2)]) continue;
            a[jx[2]][jy[2]] = t2;
            pair<pair<int, int>, pair<int, int> > ans = check();
            if (ans.first.first != -1) {
              cout << "Solution exists." << endl;
              cout << "Replace J1 with " << t1.num << t1.col << " and J2 with "
                   << t2.num << t2.col << "." << endl;
              cout << "Put the first square to ";
              outp(ans.first);
              cout << "Put the second square to ";
              outp(ans.second);
              return 0;
            }
          }
        }
        vis[ctos(t1)] = 0;
      }
    }
    cout << "No solution." << endl;
    return 0;
  }
  return 0;
}