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 std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::sort;
using std::vector;
const int maxN = 17 + 5;
const set<char> ranks = {'A', '2', '3', '4', '5', '6', '7',
                         '8', '9', 'T', 'J', 'Q', 'K'};
const set<char> suits = {'C', 'D', 'H', 'S'};
struct Card {
  char rk, st;
  Card() {}
  Card(int rk, int st) : rk(rk), st(st) {}
  friend bool operator<(const Card &A, const Card &B) {
    return A.rk != B.rk ? A.rk < B.rk : A.st < B.st;
  }
} a[maxN][maxN], t[maxN][maxN];
struct Point {
  int x, y;
  Point() {}
  Point(int x, int y) : x(x), y(y) {}
} joker[3];
vector<Point> empty;
set<Card> cards;
int n, m;
int jks = 0;
char words[1000];
void initialize() {
  for (char x : ranks) {
    for (char y : suits) {
      cards.insert(Card(x, y));
    }
  }
  cin >> n >> m;
  memset(joker, 0, sizeof(joker));
  empty.clear();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      char s[10];
      cin >> s;
      if (suits.count(s[1])) {
        t[i][j] = a[i][j] = (Card){s[0], s[1]};
        cards.erase(Card(s[0], s[1]));
      } else {
        joker[s[1] - '0'] = (Point){i, j};
        jks |= (s[1] - '0');
        if (s[1] == '2')
          empty.push_back(Point(i, j));
        else
          empty.insert(empty.begin(), Point(i, j));
      }
    }
}
bool ok(int x, int y) {
  set<char> rk, st;
  rk.clear();
  st.clear();
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      rk.insert(t[x + i][y + j].rk);
      st.insert(t[x + i][y + j].st);
    }
  }
  if (rk.size() == 9 || st.size() == 1)
    return true;
  else
    return false;
}
bool try_sol() {
  for (int x1 = 1; x1 + 2 <= n; ++x1) {
    for (int y1 = 1; y1 + 2 <= m; ++y1)
      if (ok(x1, y1)) {
        for (int x2 = 1; x2 + 2 <= n; ++x2) {
          for (int y2 = 1; y2 + 2 <= m; ++y2)
            if (ok(x2, y2)) {
              if (!(std::min(x1, x2) + 2 >= std::max(x1, x2) &&
                    std::min(y1, y2) + 2 >= std::max(y1, y2))) {
                printf("Solution exists.\n");
                printf("%s\n", words);
                printf("Put the first square to (%d, %d).\n", x1, y1);
                printf("Put the second square to (%d, %d).\n", x2, y2);
                return true;
              }
            }
        }
      }
  }
  return false;
}
bool solve() {
  assert(__builtin_popcount(jks) == (int)empty.size());
  if (empty.size() == 0) {
    sprintf(words, "There are no jokers.");
    return try_sol();
  } else if (empty.size() == 1) {
    int id = -1;
    if (jks == 1)
      id = 1;
    else
      id = 2;
    for (Card c : cards) {
      sprintf(words, "Replace J%d with %c%c.", id, c.rk, c.st);
      t[empty[0].x][empty[0].y] = c;
      if (try_sol()) return true;
    }
  } else {
    for (auto i = cards.begin(); i != cards.end(); ++i) {
      for (auto j = cards.begin(); j != cards.end(); ++j)
        if (i != j) {
          sprintf(words, "Replace J1 with %c%c and J2 with %c%c.", i->rk, i->st,
                  j->rk, j->st);
          t[empty[0].x][empty[0].y] = *i;
          t[empty[1].x][empty[1].y] = *j;
          if (try_sol()) return true;
        }
    }
  }
  return false;
}
int main() {
  initialize();
  if (!solve()) {
    printf("No solution.\n");
  }
  return 0;
}