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;
string card;
int j1x = 20, j1y = 20;
int j2x = 20, j2y = 20;
int sq1x = 20, sq1y = 20;
int sq2x = 20, sq2y = 20;
vector<vector<int> > field(50);
string suits = "HCDS";
string faces = "AT23456789JQK";
void input() {
  cin >> n >> m;
  for (int x = 0; x < 30; ++x) {
    field[x].resize(30);
  }
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < m; ++y) {
      cin >> card;
      int i, j;
      if (card[0] == 'J') {
        if (card[1] == '1' || card[1] == '2') {
          if (card[1] == '1') {
            j1x = x;
            j1y = y;
          } else {
            j2x = x;
            j2y = y;
          }
          continue;
        }
      }
      for (i = 0; i < 13; ++i) {
        if (card[0] == faces[i]) {
          break;
        }
      }
      for (j = 0; j < 13; ++j) {
        if (card[1] == suits[j]) {
          break;
        }
      }
      field[x][y] = j * 13 + i;
    }
  }
}
bool check() {
  int squares_found = 0;
  bool used[52] = {false};
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < m; ++y) {
      int code = field[x][y];
      if (used[code]) {
        return false;
      }
      used[code] = true;
    }
  }
  for (int x = 0; x + 2 < n; ++x) {
    for (int y = 0; y + 2 < m; ++y) {
      int suits[4] = {0};
      int faces[13] = {0};
      for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
          ++suits[field[x + i][y + j] / 13];
          ++faces[field[x + i][y + j] % 13];
        }
      }
      bool suit_valid = true;
      for (int f = 0; f < 4; ++f) {
        if (suits[f] != 0 && suits[f] != 9) {
          suit_valid = false;
          break;
        }
      }
      bool faces_valid = true;
      for (int f = 0; f < 13; ++f) {
        if (faces[f] > 1) {
          faces_valid = false;
          break;
        }
      }
      if (suit_valid || faces_valid) {
        ++squares_found;
        if (squares_found == 1) {
          sq1x = x + 1;
          sq1y = y + 1;
        }
        if (squares_found == 2) {
          sq2x = x + 1;
          sq2y = y + 1;
          bool x_overlap = (sq2x >= sq1x && sq2x <= sq1x + 2) ||
                           (sq1x >= sq2x && sq1x <= sq2x + 2);
          bool y_overlap = (sq2y >= sq1y && sq2y <= sq1y + 2) ||
                           (sq1y >= sq2y && sq1y <= sq2y + 2);
          if (x_overlap && y_overlap) {
            squares_found -= 1;
            sq2x = -1;
            sq2y = -1;
          } else {
            return true;
          }
        }
      }
    }
  }
  return false;
}
string card_name(int i) {
  int suit = i / 13;
  int face = i % 13;
  string s;
  s += faces[face];
  s += suits[suit];
  return s;
}
void solve() {
  for (int i = 0; i < 52; ++i) {
    field[j1x][j1y] = i;
    for (int j = 0; j < 52; ++j) {
      field[j2x][j2y] = j;
      if (check()) {
        cout << "Solution exists." << endl;
        if (j1x == 20 && j2x == 20) {
          cout << "There are no jokers." << endl;
        } else if (j1x != 20 && j2x != 20) {
          cout << "Replace J1 with " << card_name(i) << " and J2 with "
               << card_name(j) << "." << endl;
        } else if (j1x != 20) {
          cout << "Replace J1 with " << card_name(i) << "." << endl;
        } else {
          cout << "Replace J2 with " << card_name(j) << "." << endl;
        }
        cout << "Put the first square to (" << sq1x << ", " << sq1y << ")."
             << endl;
        cout << "Put the second square to (" << sq2x << ", " << sq2y << ")."
             << endl;
        return;
      }
    }
  }
  cout << "No solution." << endl;
}
int main() {
  input();
  solve();
  return 0;
}