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.awt.Point;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Contest {

	static final Random random = new Random();

	static PrintWriter out = new PrintWriter(System.out);

	static class Block {
		Point st, en;

		Block(Point st, Point en) {
			this.st = st;
			this.en = en;
		}
	}

	static int n, m;
	static HashMap<String, Boolean> cards = new HashMap<>();

	static String[] ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A" };
	static String[] suits = { "C", "D", "H", "S" };
	static String[] all_cards = new String[54];

	static String[][] deck;

	static ArrayList<Block> blocks = new ArrayList<>();

	static String replace_j1 = "", replace_j2 = "";

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);

		generate_all_cards();

		n = sc.nextInt();
		m = sc.nextInt();

		deck = new String[n][m];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				deck[i][j] = sc.next();
				cards.put(deck[i][j], true);
				if (isValid(new Point(i, j))) {
					blocks.add(new Block(new Point(i, j), new Point(i + 2, j + 2)));
				}
			}
		}

		boolean solved = false;

		// Check all 3x3 blocks
		for (int i = 0; i < blocks.size(); i++) {
			for (int j = i + 1; j < blocks.size(); j++) {
				Block b1 = blocks.get(i), b2 = blocks.get(j);

				if (isOverLapping(b1, b2))
					continue;

				if (isSolvable(b1) && isSolvable(b2)) {
					cards.put(replace_j1, true);
					cards.put(replace_j2, true);
					if(cards.get("J1") || cards.get("J2")) {
						if(cards.get("J1")) {
							for(String str : all_cards) {
								if(!cards.get(str) && !str.equals("J1") && !str.equals("J2")) {
									replace_j1 = str;
									cards.put(str, true);
									cards.put("J1", false);
									break;
								}
							}
						}
						
						if(cards.get("J2")) {
							for(String str : all_cards) {
								if(!cards.get(str) && !str.equals("J1") && !str.equals("J2")) {
									replace_j2 = str;
									cards.put(str, true);
									cards.put("J2", false);
									break;
								}
							}
						}
						
						if(cards.get("J1") || cards.get("J2")) {
							init();
							continue;
						}
						
					}
					solved = true;
					out.println("Solution exists.");

					boolean j1 = replace_j1.equals(""), j2 = replace_j2.equals("");

					// Replace what's needed
					if (j1 && j2)
						out.println("There are no jokers.");
					else if (j1 && !j2 || !j1 && j2) {
						out.println(
								"Replace " + (!j1 ? "J1 " : "J2 ") + "with " + (!j1 ? replace_j1 : replace_j2) + ".");
					} else {
						out.println("Replace " + "J1 " + "with " + replace_j1
								+ " and " + "J2 " + "with " + replace_j2 + ".");
					}

					out.println("Put the first square to (" + (b1.st.x + 1) + ", " + (b1.st.y + 1) + ").");
					out.println("Put the second square to (" + (b2.st.x + 1) + ", " + (b2.st.y + 1) + ").");
					break;
				} else
					init();
			}
			if (solved)
				break;
		}

		if (!solved) {
			System.out.println("No solution.");
		}

		out.flush();
	}

	static void init() {
		for (int i = 0, k = 0; i < ranks.length; i++) {
			for (int j = 0; j < suits.length && k < 52; j++, k++) {
				cards.put(all_cards[k], false);
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cards.put(deck[i][j], true);
			}
		}

		replace_j1 = "";
		replace_j2 = "";
	}

	static boolean isSolvable(Block b1) {
		TreeSet<Character> for_ranks = new TreeSet<>(), for_suits = new TreeSet<>();

		boolean joker1 = false, joker2 = false;
		Point p1, p2;

		for (int i = b1.st.x; i <= b1.en.x; i++) {
			for (int j = b1.st.y; j <= b1.en.y; j++) {
				if (deck[i][j].equals("J1")) {
					joker1 = true;
					p1 = new Point(i, j);
					continue;
				}

				if (deck[i][j].equals("J2")) {
					joker2 = true;
					p2 = new Point(i, j);
					continue;
				}

				for_ranks.add(deck[i][j].charAt(0));
				for_suits.add(deck[i][j].charAt(1));
			}
		}

		if (!cards.get("J1"))
			joker1 = false;

		if (!cards.get("J2"))
			joker2 = false;

		if (for_ranks.size() == 9 || (for_suits.size() == 1 && !joker1 && !joker2))
			return true;

		if (for_ranks.size() == 8 && (joker1 || joker2)) {
			// We need to swap the joker with a card with the same rank
			for (int i = 0; i < all_cards.length - 2; i++) {
				if (cards.get(all_cards[i]))
					continue;

				if (for_ranks.contains(all_cards[i].charAt(0)))
					continue;

				if (joker1) {
					cards.put("J1", false);
				} else
					cards.put("J2", false);

				if (joker1) {
					replace_j1 = all_cards[i];
				} else
					replace_j2 = all_cards[i];

				if (joker1)
					joker1 = false;
				else
					joker2 = false;

				cards.put(all_cards[i], true);

				return true;
			}
		}

		if (for_ranks.size() == 7 && joker1 && joker2) {

			for (int i = 0; i < all_cards.length - 2; i++) {
				if (cards.get(all_cards[i]))
					continue;
				if (for_ranks.contains(all_cards[i].charAt(0)))
					continue;

				if (joker1) {
					cards.put("J1", false);
				} else
					cards.put("J2", false);
				
				if (joker1) {
					replace_j1 = all_cards[i];
				} else
					replace_j2 = all_cards[i];

				cards.put(all_cards[i], true);
				for_ranks.add(all_cards[i].charAt(0));

				if (!joker1)
					return true;

				if (joker1)
					joker1 = false;
			}
		}

		if (for_suits.size() == 1 && (joker1 || joker2)) {
			for (int i = 0; i < all_cards.length - 2; i++) {
				if (cards.get(all_cards[i]))
					continue;
				if (!for_suits.contains(all_cards[i].charAt(1)))
					continue;
				
				if (joker1) {
					cards.put("J1", false);
				} else
					cards.put("J2", false);

				if (joker1) {
					replace_j1 = all_cards[i];
				} else
					replace_j2 = all_cards[i];

				cards.put(all_cards[i], true);

				if (joker1 && joker2)
					joker1 = false;
				else
					return true;
			}
		}
		return false;
	}

	static void generate_all_cards() {
		for (int i = 0, k = 0; i < ranks.length; i++) {
			for (int j = 0; j < suits.length && k < 52; j++, k++) {
				all_cards[k] = ranks[i] + suits[j];
				cards.put(all_cards[k], false);
			}
		}
		all_cards[52] = "J1";
		cards.put(all_cards[52], false);
		all_cards[53] = "J2";
		cards.put(all_cards[53], false);
	}

	static boolean isValid(Point st) {
		return st.x + 2 < n && st.y + 2 < m;
	}

	static boolean isOverLapping(Block b1, Block b2) {
		Point left_top = b1.st, left_bottom = new Point(b1.st.x + 2, b1.st.y), right_bottom = b1.en,
				right_top = new Point(b1.en.x - 2, b1.en.y);

		return (contains(left_top, b2) || contains(left_bottom, b2) || contains(right_top, b2)
				|| contains(right_bottom, b2));
	}

	static boolean contains(Point p1, Block b1) {
		return p1.x >= b1.st.x && p1.y >= b1.st.y && p1.x <= b1.en.x && p1.y <= b1.en.y;
	}

	static void Arrayssort(int[] a) {
		int n = a.length;// shuffle, then sort
		for (int i = 0; i < n; i++) {
			int oi = random.nextInt(n);
			int temp = a[oi];
			a[oi] = a[i];
			a[i] = temp;
		}
		java.util.Arrays.sort(a);
	}

	private static class Scanner {
		public BufferedReader reader;
		public StringTokenizer st;

		public Scanner(InputStream file) throws FileNotFoundException {
			reader = new BufferedReader(new InputStreamReader(file));
			st = null;
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String line = reader.readLine();
					if (line == null)
						return null;
					st = new StringTokenizer(line);
				} catch (Exception e) {
					throw (new RuntimeException());
				}
			}
			return st.nextToken();
		}

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() throws IOException {
			return reader.readLine();
		}
	}

}