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>
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
const long long N = 20;
const long long mod = 1000000007;
using namespace std;
void file() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void zuka() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n, m;
string input[N][N] = {};
bool overlap(int i1, int j1, int i2, int j2) {
  if (i2 > i1 + 2 || i1 > i2 + 2) return false;
  if (j2 > j1 + 2 || j1 > j2 + 2) return false;
  return true;
}
set<string> pre() {
  char suits[4] = {'C', 'D', 'H', 'S'};
  char ranks[13] = {'2', '3', '4', '5', '6', '7', '8',
                    '9', 'T', 'J', 'Q', 'K', 'A'};
  set<string> cards;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      string c = "";
      c = ranks[j];
      c += suits[i];
      cards.insert(c);
    }
  }
  return cards;
}
map<pair<int, int>, vector<pair<int, int>>> pre2() {
  map<pair<int, int>, vector<pair<int, int>>> squares;
  for (int i = 1; i <= n - 2; i++) {
    for (int j = 1; j <= m - 2; j++) {
      for (int si = 1; si <= n - 2; si++) {
        for (int sj = 1; sj <= m - 2; sj++) {
          if (!overlap(i, j, si, sj) && si + 2 <= n && sj + 2 <= m) {
            map<char, int> freq1, freq2;
            bool s1 = true, s2 = true;
            for (int y = i; y <= i + 2; y++) {
              for (int x = j; x <= j + 2; x++) {
                if (input[y][x] != "J1" && input[y][x] != "J2")
                  freq1[input[y][x][0]]++;
              }
            }
            for (int y = si; y <= si + 2; y++) {
              for (int x = sj; x <= sj + 2; x++) {
                if (input[y][x] != "J1" && input[y][x] != "J2")
                  freq2[input[y][x][0]]++;
              }
            }
            for (auto x : freq1) {
              if (x.second > 1) {
                s1 = false;
                break;
              }
            }
            for (auto x : freq2) {
              if (x.second > 1) {
                s2 = false;
                break;
              }
            }
            if (s1 && s2) squares[{i, j}].push_back({si, sj});
          }
        }
      }
    }
  }
  return squares;
}
int main() {
  cin >> n >> m;
  set<string> cards = pre();
  vector<pair<string, pair<int, int>>> jokers;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> input[i][j];
      cards.erase(input[i][j]);
      if (input[i][j] == "J1" || input[i][j] == "J2")
        jokers.push_back({input[i][j], {i, j}});
    }
  }
  map<pair<int, int>, vector<pair<int, int>>> squares = pre2();
  if (jokers.size() == 2) {
    int y1, y2, x1, x2;
    string j1 = "", j2 = "";
    bool done = false;
    for (auto c1 : cards) {
      j1 = c1;
      input[jokers[0].second.first][jokers[0].second.second] = c1;
      for (auto c2 : cards) {
        if (c2 == c1) continue;
        j2 = c2;
        input[jokers[1].second.first][jokers[1].second.second] = c2;
        for (auto i = squares.begin(); i != squares.end(); i++) {
          for (int j = 0; j < i->second.size(); j++) {
            int s1i = i->first.first, s1j = i->first.second;
            int s2i = i->second[j].first, s2j = i->second[j].second;
            map<char, int> freq1, freq2;
            bool s1 = true, s2 = true;
            for (int y = s1i; y <= s1i + 2; y++)
              for (int x = s1j; x <= s1j + 2; x++) freq1[input[y][x][0]]++;
            for (int y = s2i; y <= s2i + 2; y++)
              for (int x = s2j; x <= s2j + 2; x++) freq2[input[y][x][0]]++;
            for (auto x : freq1) {
              if (x.second > 1) {
                s1 = false;
                break;
              }
            }
            for (auto x : freq2) {
              if (x.second > 1) {
                s2 = false;
                break;
              }
            }
            if (s1 && s2) {
              done = true;
              y1 = s1i, x1 = s1j;
              y2 = s2i, x2 = s2j;
              break;
            }
          }
          if (done) break;
        }
        if (done) break;
      }
      if (done) break;
    }
    if (done) {
      if (jokers[0].first == "J2") swap(j1, j2);
      cout << "Solution exists.\n";
      cout << "Replace J1 with " << j1 << " and J2 with " << j2 << ".\n";
      cout << "Put the first square to (" << y1 << ", " << x1 << ").\n";
      cout << "Put the second square to (" << y2 << ", " << x2 << ").\n";
    } else
      cout << "No solution.";
  } else if (jokers.size() == 1) {
    int y1, y2, x1, x2;
    string j1 = "";
    bool done = false;
    for (auto c1 : cards) {
      j1 = c1;
      input[jokers[0].second.first][jokers[0].second.second] = c1;
      for (auto i = squares.begin(); i != squares.end(); i++) {
        for (int j = 0; j < i->second.size(); j++) {
          int s1i = i->first.first, s1j = i->first.second;
          int s2i = i->second[j].first, s2j = i->second[j].second;
          map<char, int> freq1, freq2;
          bool s1 = true, s2 = true;
          for (int y = s1i; y <= s1i + 2; y++)
            for (int x = s1j; x <= s1j + 2; x++) freq1[input[y][x][0]]++;
          for (int y = s2i; y <= s2i + 2; y++)
            for (int x = s2j; x <= s2j + 2; x++) freq2[input[y][x][0]]++;
          for (auto x : freq1) {
            if (x.second > 1) {
              s1 = false;
              break;
            }
          }
          for (auto x : freq2) {
            if (x.second > 1) {
              s2 = false;
              break;
            }
          }
          if (s1 && s2) {
            done = true;
            y1 = s1i, x1 = s1j;
            y2 = s2i, x2 = s2j;
            break;
          }
        }
        if (done) break;
      }
      if (done) break;
    }
    if (done) {
      cout << "Solution exists.\n";
      cout << "Replace " << jokers[0].first << " with " << j1 << ".\n";
      cout << "Put the first square to (" << y1 << ", " << x1 << ").\n";
      cout << "Put the second square to (" << y2 << ", " << x2 << ").\n";
    } else
      cout << "No solution.";
  } else {
    if (squares.size()) {
      int y1 = squares.begin()->first.first, x1 = squares.begin()->first.second;
      int y2 = squares.begin()->second[0].first,
          x2 = squares.begin()->second[0].second;
      cout << "Solution exists.\n";
      cout << "There are no jokers.\n";
      cout << "Put the first square to (" << y1 << ", " << x1 << ").\n";
      cout << "Put the second square to (" << y2 << ", " << x2 << ").\n";
    } else
      cout << "No solution.";
  }
}