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.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	String[] cardStr = new String [52];
	
	int rNum;
	int cNum;
	int[][] cards;
	
	int dsz = 0;
	int[] deck;
	
	void run() throws IOException {
		int k = 0;
		char[] rnk = "23456789TJQKA".toCharArray();
		char[] sts = "CDHS".toCharArray();
		for (char r : rnk) for (char s : sts) cardStr[k++] = r + "" + s; 
		
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		rNum = nextInt();
		cNum = nextInt();
		cards = new int [rNum][cNum];
		for (int r = 0; r < rNum; r++)
			for (int c = 0; c < cNum; c++)
				cards[r][c] = getNum(nextToken());
		deck = new int [54];
		lp: for (int card = 0; card < 52; card++) {
			for (int[] row : cards) for (int x : row) if (x == card) continue lp;
			deck[dsz++] = card;
		}
		deck = Arrays.copyOf(deck, dsz);
		int jcnt = 0;
		int[] jn = new int [2];
		int[] jr = new int [2];
		int[] jc = new int [2];
		for (int r = 0; r < rNum; r++)
			for (int c = 0; c < cNum; c++)
				if (cards[r][c] < 0) {
					jn[jcnt] = -cards[r][c];
					jr[jcnt] = r;
					jc[jcnt] = c;
					jcnt++;
				}
		List<String> ans = new ArrayList<String>(10);
		int[][] pos = null;
		if (jcnt == 0) {
			if ((pos = findAnswer()) != null)
				ans.add("There are no jokers.");
		} else if (jcnt == 1) {
			lp: for (int j1 = 0; j1 < dsz; j1++) {
				cards[jr[0]][jc[0]] = deck[j1];
				if ((pos = findAnswer()) != null) {
					ans.add("Replace J" + jn[0] + " with " + getCard(deck[j1]) + ".");
					break lp;
				}
			}
		} else if (jcnt == 2) {
			if (jn[0] == 2) {
				swap(jn, 0, 1);
				swap(jr, 0, 1);
				swap(jc, 0, 1);
			}
			lp: for (int j1 = 0; j1 < dsz; j1++) {
				cards[jr[0]][jc[0]] = deck[j1];
				for (int j2 = 0; j2 < dsz; j2++) {
					cards[jr[1]][jc[1]] = deck[j2];
					if (j1 == j2) continue;
					if ((pos = findAnswer()) != null) {
						ans.add("Replace J1 with " + getCard(deck[j1]) + " and J2 with " + getCard(deck[j2]) + ".");
						break lp;
					}
				}
			}
		}
		
		if (pos != null) {
			ans.add("Put the first square to (" + pos[0][0] + ", " + pos[0][1] + ").");
			ans.add("Put the second square to (" + pos[1][0] + ", " + pos[1][1] + ").");
		}
		
		if (ans.size() > 0) {
			out.println("Solution exists.");
			for (String line : ans) out.println(line);
		} else {
			out.println("No solution.");
		}
		
		out.close();
	}
	
	int[] cr = new int [52];
	int[] cc = new int [52];
	
	int[][] findAnswer() {
		int cn = 0;
		for (int r = 0; r + 3 <= rNum; r++)
			for (int c = 0; c + 3 <= cNum; c++)
				if (good(r, c)) {
					cr[cn] = r;
					cc[cn] = c;
					cn++;
				}
		for (int r1 = 0; r1 < cn; r1++)
			for (int r2 = 0; r2 < cn; r2++)
				if (!its(cr[r1], cc[r1], cr[r1] + 2, cc[r1] + 2, cr[r2], cc[r2], cr[r2] + 2, cc[r2] + 2))
					return new int[][] { { cr[r1] + 1, cc[r1] + 1 }, { cr[r2] + 1, cc[r2] + 1 } };
		return null;
	}
	
	boolean its(int t1, int l1, int b1, int r1, int t2, int l2, int b2, int r2) {
		return its(t1, b1, t2, b2) && its(l1, r1, l2, r2);
	}

	boolean its(int l1, int r1, int l2, int r2) {
		return min(r1, r2) >= max(l1, l2);
	}

	boolean good(int r, int c) {
		return sameSuit(r, c) || allDiff(r, c);
	}

	boolean sameSuit(int r, int c) {
		int suit = cards[r][c] & 3;
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (suit != (cards[r + i][c + j] & 3))
					return false;
		return true;
	}

	int[] rnkCnt = new int [13];
	boolean allDiff(int r, int c) {
		fill(rnkCnt, 0);
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (++rnkCnt[cards[r + i][c + j] >> 2] > 1)
					return false;
		return true;
	}

	String getCard(int code) {
		if (code < 0) return "J" + (-code);
		return cardStr[code];
	}

	int getNum(String s) {
		if (s.equals("J1")) return -1;
		if (s.equals("J2")) return -2;
		return getRank(s.charAt(0)) * 4 + getSuit(s.charAt(1));
	}

	int getRank(char c) {
		if (c == 'A') return 12;
		if (c == 'K') return 11;
		if (c == 'Q') return 10;
		if (c == 'J') return  9;
		if (c == 'T') return  8;
		return c - '2';
	}
	
	int getSuit(char c) {
		if (c == 'C') return 0;
		if (c == 'D') return 1;
		if (c == 'H') return 2;
		if (c == 'S') return 3;
		return -1;
	}
	
	void swap(int[] a, int i, int j) {
		int t = a[i];
		a[i] = a[j];
		a[j] = t;
	}
	
	/*************************************************************** 
	 * Utility
	 **************************************************************/
	long b2mb(long b) {
		return b >> 20;
	}
	
	void checkMemory() {
		System.err.println(b2mb(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) + "/" + b2mb(Runtime.getRuntime().totalMemory()) + " MB");
	}
	
	/*************************************************************** 
	 * Input 
	 **************************************************************/
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}