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

Solution:
def get_cards():
	n,m = map(int,input().split())
	lis = [[]]*n
	for i in range(n):
		lis[i] = list(map(str,input().split()))
	return (n,m,lis)

def find_remains(cards):
	remains = []
	ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K","A"]
	suits = ["C", "D", "H","S"]
	for r in ranks:
		for s in suits:
			remains.append(r+s)
	remains += ["J1","J2"]
	for i in range(cards[0]):
		for j in range(cards[1]):
			remains.remove(cards[2][i][j])
	return remains

def condition_1(ranks):
	r = set(ranks)
	if len(r) < len(ranks):
		return 1
	else:
		return 0
			
def condition_2(suits):
	r = set(suits)
	if len(r) == 1:
		return 0
	else:
		return 1

def find_solution(cards):
	lis = cards[2]
	positions = []
	result = 1
	position = []
	for i in range(cards[0]-2):
		for j in range(cards[1]-2):
			positions.append((i,j))
	for p in positions:
		positions_2 = positions[:]
		if result == 0:
				break
		i = p[0]
		j = p[1]
		nine_1 = [lis[i][j],lis[i][j+1],lis[i][j+2],lis[i+1][j],lis[i+1][j+1],lis[i+1][j+2],lis[i+2][j],lis[i+2][j+1],lis[i+2][j+2]]
		nine_1_p = []
		for a in range(-2,3):
			for b in range(-2,3):
				nine_1_p.append((i+a,j+b))
		for c in nine_1_p:
			if c in positions_2:
				positions_2.remove(c)
		for q in positions_2:
			if result == 0:
				break
			i = q[0]
			j = q[1]
			nine_2 = [lis[i][j],lis[i][j+1],lis[i][j+2],lis[i+1][j],lis[i+1][j+1],lis[i+1][j+2],lis[i+2][j],lis[i+2][j+1],lis[i+2][j+2]]
		
			ranks_1,ranks_2 = [],[]
			suits_1,suits_2 = [],[]
			for card in nine_1:
				ranks_1.append(card[0])
				suits_1.append(card[1])
			result_1_1 = condition_1(ranks_1)
			result_1_2 = condition_2(suits_1)
			for card in nine_2:
				ranks_2.append(card[0])
				suits_2.append(card[1])
			result_2_1 = condition_1(ranks_2)
			result_2_2 = condition_2(suits_2)
			if result_1_1*result_1_2 == 0 and result_2_1*result_2_2 == 0:
				result = 0
				position = [p,q]
	result = [result,position]
	return result

def find_Jocker(cards):
	n = cards[0]
	m = cards[1]
	J1,J2 = 0,0
	for i in range(n):
		for j in range(m):
			if cards[2][i][j] == "J1":
				J1 = (i,j)
			if cards[2][i][j] == "J2":
				J2 = (i,j)
	positions = (J1,J2)
	return positions
	


cards = get_cards()
if cards[0] < 3 or cards[1] < 3:
	result = [1]
elif cards[0] < 6 and cards[1] < 6:
	result = [1]
else:
	remains = find_remains(cards)
	jocker = find_Jocker(cards)
	changed = [0,0]
	if jocker[0] == 0 and jocker[1] == 0:
		result = find_solution(cards)
	elif jocker[0] != 0 and jocker[1] == 0:
		remains.remove("J2")
		for remain in remains:
			cards[2][jocker[0][0]][jocker[0][1]] = remain
			result = find_solution(cards)
			if result[0] == 0:
				changed = [remain,0]
				break
	elif jocker[1] != 0 and jocker[0] == 0:
		remains.remove("J1")
		for remain in remains:
			cards[2][jocker[1][0]][jocker[1][1]] = remain
			result = find_solution(cards)
			if result[0] == 0:
				changed = [0,remain]
				break	 
	else:
		remains_2 = remains[:]
		for remain_1 in remains:
			cards[2][jocker[1][0]][jocker[1][1]] = remain_1
			remains_2.remove(remain_1)
			for remain_2 in remains_2:
				cards[2][jocker[0][0]][jocker[0][1]] = remain_2
				result = find_solution(cards)
				if result[0] == 0:
					changed[0] = remain_2
					break
			remains_2 = remains[:]
			if result[0] == 0:
				changed[1] = remain_1
				break

if result[0] == 1:
	print("No solution.")
if result[0] == 0:
	print("Solution exists.")
	if changed[0] != 0 and changed[1] != 0:
		print("Replace J1 with "+changed[0]+" and J2 with "+changed[1]+".")
	elif changed[0] != 0:
		print("Replace J1 with "+changed[0]+".")
	elif changed[1] != 0:
		print("Replace J2 with "+changed[1]+".")
	else:
		print("There are no jokers.")
	print("Put the first square to ("+str(result[1][0][0]+1)+", "+str(result[1][0][1]+1)+").")
	print("Put the second square to ("+str(result[1][1][0]+1)+", "+str(result[1][1][1]+1)+").")