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.IOException;
import java.io.InputStreamReader;

public class D {
    static Point Fst;
    static Point Snd;

    public static int rank(char x) {
        if (Character.isDigit(x))
            return x - '0';
        switch (x) {
        case 'A':
            return 0;
        case 'K':
            return 1;
        case 'Q':
            return 10;
        case 'J':
            return 11;
        default:
            return 12;
        }
    }

    public static int suite(char x) {
        if (Character.isDigit(x))
            return x - '0';
        switch (x) {
        case 'S':
            return 0;
        case 'C':
            return 1;
        case 'H':
            return 2;
        default:
            return 3;
        }
    }

    public static boolean Can(Card[][] A) {
        int n = A.length;
        int m = A[0].length;
        boolean[][] V = new boolean[n][m];
        for (int i = 0; i + 3 <= n; i++)
            for (int j = 0; j + 3 <= m; j++) {
                int[] S = new int[4];
                int[] R = new int[13];
                int s = 0;
                int r = 0;
                for (int k = 0; k < 3; k++)
                    for (int l = 0; l < 3; l++) {
                        S[A[i + k][j + l].suite]++;
                        R[A[i + k][j + l].rank]++;
                    }
                for (int k = 0; k < 4; k++)
                    if (S[k] != 0)
                        s++;
                for (int k = 0; k < 13; k++)
                    if (R[k] > 1)
                        r++;
                V[i][j] = (s == 1) | (r == 0);
            }
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                for (int k = i; k < n; k++)
                    for (int l = 0; l < m; l++) {
                        if (k < i + 3
                                && ((l >= j && l < j + 3) || (l + 2 >= j && l + 2 <= j + 2)))
                            continue;
                        if (V[i][j] && V[k][l]) {
                            Fst = new Point(i + 1, j + 1);
                            Snd = new Point(k + 1, l + 1);
                            return true;
                        }
                    }
            }
        return false;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        char[] C = new char[13];
        C[0] = 'A';
        C[1] = 'K';
        C[10] = 'Q';
        C[11] = 'J';
        C[12] = 'T';
        for (int i = 2; i < 10; i++)
            C[i] = (char) (i + '0');
        char[] Su = new char[4];
        Su[0] = 'S';
        Su[1] = 'C';
        Su[2] = 'H';
        Su[3] = 'D';
        String[] S = in.readLine().split(" ");
        int n = Integer.parseInt(S[0]);
        int m = Integer.parseInt(S[1]);
        Card[][] A = new Card[n][m];
        boolean[][] Done = new boolean[4][13];
        Point[] J = new Point[2];
        int jo = 0;
        for (int i = 0; i < n; i++) {
            S = in.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                A[i][j] = new Card(rank(S[j].charAt(0)), suite(S[j].charAt(1)));
                Done[A[i][j].suite][A[i][j].rank] = true;
                if (A[i][j].rank == 11 && Character.isDigit(S[j].charAt(1))) {
                    J[jo++] = new Point(i, j);
                }
            }
        }
        if (jo == 0) {
            if (Can(A)) {
                System.out.println("Solution exists.\nThere are no jokers.");
                System.out.println("Put the first square to (" + Fst.x + ", "
                        + Fst.y + ").");
                System.out.println("Put the second square to (" + Snd.x + ", "
                        + Snd.y + ").");
            } else
                System.out.println("No solution.");
        } else {
            if (jo == 1) {
                int j1 = A[J[0].x][J[0].y].suite;
                for (int i = 0; i < 4; i++)
                    for (int j = 0; j < 13; j++) {
                        if (Done[i][j])
                            continue;
                        A[J[0].x][J[0].y] = new Card(j, i);
                        if (Can(A)) {
                            System.out.println("Solution exists.");
                            System.out.println("Replace J" + j1 + " with "
                                    + C[j] + Su[i] + ".");
                            System.out.println("Put the first square to ("
                                    + Fst.x + ", " + Fst.y + ").");
                            System.out.println("Put the second square to ("
                                    + Snd.x + ", " + Snd.y + ").");
                            System.exit(0);
                        }
                    }
                System.out.println("No solution.");
            } else if (jo == 2) {
                int j1 = A[J[0].x][J[0].y].suite;
                int j2 = A[J[1].x][J[1].y].suite;
                for (int i = 0; i < 4; i++)
                    for (int j = 0; j < 13; j++)
                        for (int k = 0; k < 4; k++)
                            for (int l = 0; l < 13; l++) {
                                if (Done[i][j] || Done[k][l]
                                        || (i == k && j == l))
                                    continue;
                                A[J[0].x][J[0].y] = new Card(j, i);
                                A[J[1].x][J[1].y] = new Card(l, k);
                                if (Can(A)) {
                                    System.out.println("Solution exists.");
                                    if (j1 == 1)
                                        System.out.println("Replace J" + j1
                                                + " with " + C[j] + Su[i]
                                                + " and J" + j2 + " with "
                                                + C[l] + Su[k] + ".");
                                    else
                                        System.out.println("Replace J" + j2
                                                + " with " + C[l] + Su[k]
                                                + " and J" + j1 + " with "
                                                + C[j] + Su[i] + ".");
                                    System.out
                                            .println("Put the first square to ("
                                                    + Fst.x
                                                    + ", "
                                                    + Fst.y
                                                    + ").");
                                    System.out
                                            .println("Put the second square to ("
                                                    + Snd.x
                                                    + ", "
                                                    + Snd.y
                                                    + ").");
                                    System.exit(0);
                                }
                            }
                System.out.println("No solution.");
            }
        }
    }
}

class Card {
    int rank;
    int suite;

    public Card(int x, int y) {
        rank = x;
        suite = y;
    }
}