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

/**
 * @author Egor Kulikov (egor@egork.net)
 * @author Alexey Safronov (safronov.aa@gmail.com)
 */
public class Round65 {
	@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
	private InputReader in;
	private PrintWriter out;
	
	private int[] check_solution(String[][] field) {
		int N = field.length;
		int M = field[0].length;
		int[] result = {-1, -1, -1, -1};
		
		for(int i1 = 0; i1 < N; i1++) {
			for(int j1 = 0; j1 < M; j1++) {
				for(int i2 = 0; i2 < N; i2++) {
					for(int j2 = 0; j2 < M; j2++) {
						if(i1 + 2 < N && i2 + 2 < N && j1 + 2 < M && j2 + 2 < M) {
							if(i1 + 2 < i2 || j1 + 2 < j2) {
								boolean check11 = true;
								boolean check12 = true;
								HashSet<Character> A = new HashSet<Character>();
								HashSet<Character> B = new HashSet<Character>();
								
								for(int k1 = 0; k1 < 3; k1++) {
									for(int k2 = 0; k2 < 3; k2++) {
										char a = field[i1 + k1][j1 + k2].charAt(0);
										char b = field[i1 + k1][j1 + k2].charAt(1);
										
										if(A.contains(a)) {
											check11 = false;
										} else {
											A.add(a);
										}
										
										if(!B.contains(b) && B.size() > 0) {
											check12 = false;
										} else {
											B.add(b);
										}
									}
								}
								
								boolean check21 = true;
								boolean check22 = true;
								A.clear();
								B.clear();
								
								for(int k1 = 0; k1 < 3; k1++) {
									for(int k2 = 0; k2 < 3; k2++) {
										char a = field[i2 + k1][j2 + k2].charAt(0);
										char b = field[i2 + k1][j2 + k2].charAt(1);
										
										if(A.contains(a)) {
											check21 = false;
										} else {
											A.add(a);
										}
										
										if(!B.contains(b) && B.size() > 0) {
											check22 = false;
										} else {
											B.add(b);
										}
									}
								}
								
								if((check11 || check12) && (check21 || check22)) {
									result[0] = i1;
									result[1] = j1;
									result[2] = i2;
									result[3] = j2;
									return result;
								}
							}
						}
					}
				}
			}
		}
		
		return result;
	}

	private void solve() {
		int N = in.readInt();
		int M = in.readInt();
		
		String[] a = {"C", "D", "H", "S"};
		String[] b = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
		String[][] field = new String[N][M];
		HashMap<String, Boolean> used = new HashMap<String, Boolean>();
		
		for(int i = 0; i < b.length; i++) {
			for(int j = 0; j < a.length; j++) {
				String card = b[i] + "" + a[j];
				used.put(card, false);
			}
		}
		
		int jokers = 0;
		int j1x = 0;
		int j1y = 0;
		int j2x = 0;
		int j2y = 0;
		boolean second = false;
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				String card = in.readString();
				used.put(card, true);
				
				if(card.charAt(0) == 'J' && (card.charAt(1) == '1' || card.charAt(1) == '2')) {
					if(card.charAt(1) == '2') {
						j2x = i;
						j2y = j;
						second = true;
					} else {
						j1x = i;
						j1y = j;
					}
					++jokers;
				}
				
				field[i][j] = card;
			}
		}
		
		if(jokers == 0) {
			int[] result = check_solution(field);
			
			if(result[0] == -1) {
				out.println("No solution.");
				return;
			}
			
			out.println("Solution exists.");
			out.println("There are no jokers.");
			out.println("Put the first square to (" + (result[0] + 1) + ", " + (result[1] + 1) + ").");
			out.println("Put the second square to (" + (result[2] + 1) + ", " + (result[3] + 1) + ").");
		} else if(jokers == 1) {
			if(second) {
				j1x = j2x;
				j1y = j2y;
			}
			for(String card : used.keySet()) {
				if(!used.get(card)) {
					String[][] new_field = field.clone();
					new_field[j1x][j1y] = card;
					
					int[] result = check_solution(field);
					
					if(result[0] == -1) {
						continue;
					}
					
					out.println("Solution exists.");
					if(!second) {
						out.println("Replace J1 with " + card + ".");
					} else {
						out.println("Replace J2 with " + card + ".");
					}
					out.println("Put the first square to (" + (result[0] + 1) + ", " + (result[1] + 1) + ").");
					out.println("Put the second square to (" + (result[2] + 1) + ", " + (result[3] + 1) + ").");
					return;
				}
			}
			
			out.println("No solution.");
			return;
		} else {
			for(String card : used.keySet()) {
				if(!used.get(card)) {
					for(String card2 : used.keySet()) {
						if(!used.get(card2) && !card.equals(card2)) {
							String[][] new_field = field.clone();
							new_field[j1x][j1y] = card;
							new_field[j2x][j2y] = card2;
							
							int[] result = check_solution(field);
							
							if(result[0] == -1) {
								continue;
							}
							
							out.println("Solution exists.");
							out.println("Replace J1 with " + card + " and J2 with " + card2 + ".");
							out.println("Put the first square to (" + (result[0] + 1) + ", " + (result[1] + 1) + ").");
							out.println("Put the second square to (" + (result[2] + 1) + ", " + (result[3] + 1) + ").");
							return;
						}
					}
				}
			}
			
			out.println("No solution.");
			return;
		}
	}

	public static void main(String[] args) {
		new Round65().run();
	}

	private Round65() {
		@SuppressWarnings({"UnusedDeclaration"})
		String id = getClass().getName().toLowerCase();
		//noinspection EmptyTryBlock
		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	private void run() {
		//noinspection InfiniteLoopStatement
//		int testCount = in.readInt();
//		for (int i = 0; i < testCount; i++)
//		while (true)
		solve();
		exit();
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private void exit() {
		out.close();
		System.exit(0);
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public int[] readIntArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = readInt();
			return array;
		}

		public long[] readLongArray(int size) {
			long[] array = new long[size];
			for (int i = 0; i < size; i++)
				array[i] = readLong();
			return array;
		}

		public double[] readDoubleArray(int size) {
			double[] array = new double[size];
			for (int i = 0; i < size; i++)
				array[i] = readDouble();
			return array;
		}

		public String[] readStringArray(int size) {
			String[] array = new String[size];
			for (int i = 0; i < size; i++)
				array[i] = readString();
			return array;
		}

		public char[][] readTable(int rowCount, int columnCount) {
			char[][] table = new char[rowCount][columnCount];
			for (int i = 0; i < rowCount; i++) {
				for (int j = 0; j < columnCount; j++)
					table[i][j] = readCharacter();
			}
			return table;
		}

		public void readIntArrays(int[]... arrays) {
			for (int i = 0; i < arrays.length; i++) {
				for (int j = 0; j < arrays[0].length; j++)
					arrays[i][j] = readInt();
			}
		}
	}
}