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;
int ansy1, ansy2, ansx1, ansx2;
string joker1, joker2;
string input[N][N] = {};
vector<pair<string, pair<int, int>>> jokers;
map<pair<int, int>, vector<pair<int, int>>> squares;
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>>> group;
  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) group[{i, j}].push_back({si, sj});
          }
        }
      }
    }
  }
  return group;
}
void output(int j, bool can) {
  if (can) {
    cout << "Solution exists.\n";
    if (j == 2) {
      if (jokers[0].first == "J2") swap(joker1, joker2);
      cout << "Replace J1 with " << joker1 << " and J2 with " << joker2
           << ".\n";
    } else if (j == 1)
      cout << "Replace " << jokers[0].first << " with " << joker1 << ".\n";
    else
      cout << "There are no jokers.\n";
    cout << "Put the first square to (" << ansy1 << ", " << ansx1 << ").\n";
    cout << "Put the second square to (" << ansy2 << ", " << ansx2 << ").\n";
  } else
    cout << "No solution.";
}
int main() {
  cin >> n >> m;
  set<string> cards = pre();
  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}});
    }
  }
  squares = pre2();
  if (jokers.size() == 2) {
    bool done = false;
    for (auto c1 : cards) {
      joker1 = c1;
      input[jokers[0].second.first][jokers[0].second.second] = c1;
      for (auto c2 : cards) {
        if (c2 == c1) continue;
        joker2 = 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;
              ansy1 = s1i, ansx1 = s1j;
              ansy2 = s2i, ansx2 = s2j;
              break;
            }
          }
          if (done) break;
        }
        if (done) break;
      }
      if (done) break;
    }
    output(2, done);
  } else if (jokers.size() == 1) {
    bool done = false;
    for (auto c1 : cards) {
      joker1 = 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;
            ansy1 = s1i, ansx1 = s1j;
            ansy2 = s2i, ansx2 = s2j;
            break;
          }
        }
        if (done) break;
      }
      if (done) break;
    }
    output(1, done);
  } else {
    if (squares.size()) {
      ansy1 = squares.begin()->first.first,
      ansx1 = squares.begin()->first.second;
      ansy2 = squares.begin()->second[0].first,
      ansx2 = squares.begin()->second[0].second;
    }
    output(0, squares.size());
  }
}