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 JAVA):

Solution:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int N, M;
	static String[][] b;
	static TreeSet<String> cards;

	static boolean check(int i, int j) {
		HashSet<Character> suit = new HashSet<>(), rank = new HashSet<>();
		for (int r = i; r <= i + 2; r++)
			for (int c = j; c <= j + 2; c++) {
				suit.add(b[r][c].charAt(1));
				rank.add(b[r][c].charAt(0));
			}
		return suit.size() == 1 || rank.size() == 9;
	}

	static boolean isValid(int i, int j) {
		return i >= 0 && i < N && j >= 0 && j < M;
	}

	static boolean notIntersect(int i, int j, int r, int c) {
		return r > i + 2 || i > r + 2 || c > j + 2 || j > c + 2;
	}

	static int[] check() {
		for (int i = 0; i < N; i++)
			for (int j = 0; j < M; j++) {
				if (isValid(i + 2, j + 2) && check(i, j))
					for (int r = 0; r < N; r++)
						for (int c = 0; c < M; c++)
							if (isValid(r + 2, c + 2) && notIntersect(i, j, r, c) && check(r, c)) {
								return new int[] { i + 1, j + 1, r + 1, c + 1 };
							}
			}
		return null;
	}

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		cards = new TreeSet<>();
		String[] suits = { "C", "D", "H", "S" },
				ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A" };
		for (int i = 0; i < 4; i++)
			for (int j = 0; j < 13; j++)
				cards.add(ranks[j] + suits[i]);
		System.err.println(cards);
		b = new String[N][M];
		int jokers = 0;
		int[] jokerPos = new int[4];
		boolean J1 = false;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < M; j++) {
				String s = sc.next();
				b[i][j] = s;
				if (s.equals("J1")) {
					jokerPos[0] = i;
					jokerPos[1] = j;
					J1 = true;
					jokers++;
					continue;
				}
				if (s.equals("J2")) {
					jokerPos[2] = i;
					jokerPos[3] = j;
					jokers++;
					continue;
				}
				cards.remove(s);
			}
		if (jokers == 0) {
			int[] result = check();
			if (result != null) {
				System.out.printf(
						"Solution exists.\nThere are no jokers.\nPut the first square to (%d, %d).\nPut the second square to (%d, %d).",
						result[0], result[1], result[2], result[3]);
			} else
				System.out.println("No solution.");
		} else if (jokers == 1) {
			for (String card : cards) {
				b[jokerPos[0]][jokerPos[1]] = card;
				int[] result = check();
				if (result != null) {
					System.out.println("Solution exists.");
					System.out.printf("Replace %s with %s.\n", J1 ? "J1" : "J2", card);
					System.out.printf("Put the first square to (%d, %d).\n", result[0], result[1]);
					System.out.printf("Put the second square to (%d, %d).\n", result[2], result[3]);
					return;
				}
			}
			System.out.println("No solution.");
		} else if (jokers == 2) {
			for (String c1 : cards) {
				for (String c2 : cards) {
					if (c1.equals(c2))
						continue;
					b[jokerPos[0]][jokerPos[1]] = c1;
					b[jokerPos[2]][jokerPos[3]] = c2;
					int[] result = check();
					if (result != null) {
						System.out.println("Solution exists.");
						System.out.printf("Replace J1 with %s and J2 with %s.\n", c1, c2);
						System.out.printf("Put the first square to (%d, %d).\n", result[0], result[1]);
						System.out.printf("Put the second square to (%d, %d).\n", result[2], result[3]);
						return;
					}
				}
			}
			System.out.println("No solution.");
		}
	}

	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		public MyScanner(String filename) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(filename)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}