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.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args) throws Exception{
        new Main().run();
    }

    int h, w;

    boolean ok(String[][] a, int sy, int sx, int ey, int ex){
        HashSet<Character> used = new HashSet<Character>();
        int[] freq = new int[14];
        for(int i = sy; i < ey; i++)
            for(int j = sx; j < ex; j++){
                char rc = a[i][j].charAt(0);
                char sc = a[i][j].charAt(1);
                used.add(sc);
                if(Character.isDigit(rc)){
                    freq[rc-'0']++;
                }else if(rc == 'A'){
                    freq[1]++;
                }else if(rc == 'T'){
                    freq[10]++;
                }else if(rc == 'J'){
                    freq[11]++;
                }else if(rc == 'Q'){
                    freq[12]++;
                }else if(rc == 'K'){
                    freq[13]++;
                }
            }
        if(used.size() == 1)return true;
        /*
        int ind = 1;
        for(; ind < freq.length; ind++){
            if(freq[ind] == 1)
                break;
            else if(freq[ind] > 1)return false;
        }
        if(ind + 8 >= freq.length)return false;
        for(int i = ind; i < ind+9; i++)
            if(freq[i] != 1)return false;
        */
        for(int i = 0; i < freq.length; i++)if(freq[i] > 1)return false;
        return true;
    }

    String check(String[][] a){
        ArrayList<Integer> x = new ArrayList<Integer>();
        ArrayList<Integer> y = new ArrayList<Integer>();
        for(int i = 0; i <= h-3; i++)
            for(int j = 0; j <= w-3; j++){
                if(ok(a, i, j, i+3, j+3)){
                    y.add(i);x.add(j);
                }
            }
        int n = x.size();
        if(n < 2)return null;
        for(int i = 0; i < n; i++)
            for(int j = i+1; j < n; j++){
                int fx = x.get(i), fy = y.get(i);
                int lx = x.get(j), ly = y.get(j);
                if(
                   ((fx <= lx && lx < fx+3) || (lx <= fx && fx < lx+3)) &&
                   ((fy <= ly && ly < fy+3) || (ly <= fy && fy < ly+3))
                   )
                    continue;
                return String.format("Put the first square to (%d, %d).\nPut the second square to (%d, %d).", fy+1, fx+1, ly+1, lx+1);
            }
        return null;
    }

    void run() throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        // only sc.readLine() is available

        h = sc.nextInt();
        w = sc.nextInt();
        int j1x = -1, j1y = -1, j2x = -1, j2y =- 1;
        String[][] cards = new String[h][w];
        HashSet<String> used = new HashSet<String>();
        final char[] rank = new char[]
            {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
        final char[] suit = new char[]
            {
                'C', 'D', 'H', 'S'
            };
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                String s = sc.next();
                cards[i][j] = s;
                used.add(s);
                if(s.charAt(0) == 'J' && s.charAt(1) == '1'){
                    j1y = i; j1x = j;
                }
                if(s.charAt(0) == 'J' && s.charAt(1) == '2'){
                    j2y = i; j2x = j;
                }
            }
        }

        for(int a = 0; a < 4; a++)
            for(int b = 0; b < 13; b++){
                String j1s = "" + rank[b] + suit[a];
                if(used.contains(j1s))continue;
                if(j1y >= 0)
                    cards[j1y][j1x] = j1s;
                for(int i = 0; i < 4; i++)
                    for(int j = 0; j < 13; j++){
                        if(i == a && b == j)continue;
                        String j2s = "" + rank[j] + suit[i];
                        if(used.contains(j2s))continue;
                        if(j2y >= 0)
                            cards[j2y][j2x] = j2s;
                        String ret = check(cards);
                        if(ret != null){
                            System.out.println("Solution exists.");
                            if(j1x >= 0 && j2x >= 0){
                                System.out.printf("Replace J1 with %s and J2 with %s.\n", j1s, j2s);
                            }else if(j1x >= 0){
                                System.out.printf("Replace J1 with %s.\n", j1s);
                            }else if(j2x >= 0){
                                System.out.printf("Replace J2 with %s.\n", j2s);
                            }else{
                                System.out.printf("There are no jokers.\n");
                            }
                            System.out.println(ret);
                            return;
                        }
                    }
            }
        System.out.println("No solution.");

    }
}