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:
//package codeforces.br65;

import java.io.*;
import java.math.*;
import java.util.*;

public class ProblemC {

    String[][] a;
    int n,m;
    boolean globalfind;
    int[] pos1, pos2;

    private boolean check(int r, int c) {
        if (r < 0)
            return false;
        if (c < 0)
            return false;
        if (r > n - 3)
            return false;
        if (c > m - 3)
            return false;
        boolean onemast = true;
        boolean first = true;
        Character mast = '0';
        Set<Character> dost = new HashSet<Character>();
        boolean diffdost = true;
        for(int i=r;i<r+3;i++)
            for(int j=c;j<c+3;j++)
                if (!a[i][j].equals("J1") && !a[i][j].equals("J2")) {
                    Character ch = a[i][j].charAt(0);
                    if (dost.contains(ch))
                        diffdost = false;
                    else {
                        dost.add(ch);
                    }
                    if (first) {
                        mast = a[i][j].charAt(1);
                        first = false;
                    } else {
                        if (a[i][j].charAt(1) != mast)
                            onemast = false;
                    }
                } else {
                    onemast = false;
                    diffdost = false;
                }
        return onemast || diffdost;
    }

    public void solve() {
        boolean oj = true;

        try {
            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("C.in");
            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("C.out");
            BufferedReader br = new BufferedReader(reader);
            StreamTokenizer st = new StreamTokenizer(reader);
            PrintWriter out = new PrintWriter(writer);

            MyTokenizer tok = new MyTokenizer(br.readLine());

            n = tok.getInteger();
            m = tok.getInteger();

            a = new String[n][m];

            for(int i=0;i<n;i++) {
                tok = new MyTokenizer(br.readLine());
                for(int j=0;j<m;j++) {
                    a[i][j] = tok.getString();
                }
            }

            char[] dost = new char[] {'2', '3','4','5','6','7','8','9','T','J','Q','K','A'};
            char[] mast = new char[] {'C', 'D','H','S'};
            List<String> miss = new ArrayList<String>();
            for(int i=0;i<dost.length;i++) {
                for(int j=0;j<mast.length;j++) {
                    String card = dost[i] + "" + mast[j];
                    boolean exists = false;
                    for(int k=0;k<n;k++)
                        for(int l=0;l<m;l++) {
                            if (card.equals(a[k][l])) {
                                exists = true;
                                break;
                            }
                        }
                    if (!exists)
                        miss.add(card);
                }
            }

            List<int[]> jokers = new ArrayList<int[]>();
            List<String> js = new ArrayList<String>();
            List<String> replace = new ArrayList<String>();

            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++) {
                    if (a[i][j].equals("J1")) {
                        jokers.add(new int[] {i, j});
                        js.add(a[i][j]);
                        replace.add("");
                    }
                    if (a[i][j].equals("J2")) {
                        jokers.add(new int[] {i, j});
                        js.add(a[i][j]);
                        replace.add("");
                    }
                }

            globalfind = false;
            pos1 = new int[2];
            pos2 = new int[2];

            List<int[]> valids = new ArrayList<int[]>();
            boolean[][] bb = new boolean[n][m];
            for(int i=0;i<n-2;i++)
                for(int j=0;j<m-2;j++) {
                    if (check(i, j)) {
                        valids.add(new int[]{i, j});
                        bb[i][j] = true;
                    }
                }
            if (jokers.size() == 0) {
                for(int k=0;k<valids.size();k++)
                    for(int l=0;l<valids.size();l++)
                        if (k != l) {
                            int px1 = valids.get(k)[0];
                            int py1 = valids.get(k)[1];
                            int px2 = valids.get(l)[0];
                            int py2 = valids.get(l)[1];
                            if (Math.max(px1, px2) > Math.min(px1 + 2, px2 + 2) ||
                                Math.max(py1, py2) > Math.min(py1 + 2, py2 + 2)) {
                                if (!globalfind) {
                                    globalfind = true;
                                    pos1[0] = px1;
                                    pos1[1] = py1;
                                    pos2[0] = px2;
                                    pos2[1] = py2;
                                }
                            }
                        }
            } else if (jokers.size() == 1) {
                for(int i=0;i<miss.size();i++) {
                    int x1 = jokers.get(0)[0];
                    int y1 = jokers.get(0)[1];
                    String s1 = a[x1][y1];
                    a[x1][y1] = miss.get(i);

                    List<int[]> newvalids = new ArrayList<int[]>();
                    for(int k=0;k<valids.size();k++)
                        newvalids.add(valids.get(k));
                    boolean[][] b = new boolean[n][m];
                    for(int k=x1-2;k<=x1+2;k++)
                        for(int l=y1-2;l<=y1+2;l++) {
                            if (k >= 0 && k < n-2 && l >= 0 && l < m - 2 &&
                                !b[k][l] && !bb[k][l] && check(k, l)) {
                                newvalids.add(new int[]{k, l});
                                b[k][l] = true;
                            }
                        }

                    for(int k=0;k<newvalids.size();k++)
                        for(int l=0;l<newvalids.size();l++)
                            if (k != l) {
                                int px1 = newvalids.get(k)[0];
                                int py1 = newvalids.get(k)[1];
                                int px2 = newvalids.get(l)[0];
                                int py2 = newvalids.get(l)[1];
                                if (Math.max(px1, px2) > Math.min(px1 + 2, px2 + 2) ||
                                    Math.max(py1, py2) > Math.min(py1 + 2, py2 + 2)) {
                                    if (!globalfind) {
                                        globalfind = true;
                                        pos1[0] = px1;
                                        pos1[1] = py1;
                                        pos2[0] = px2;
                                        pos2[1] = py2;
                                        replace.set(0, miss.get(i));
                                    }
                                }
                            }

                    a[x1][y1] = s1;
                }
            } else if (jokers.size() == 2) {
                for(int i=0;i<miss.size();i++) {
                    for(int j=0;j<miss.size();j++) {
                        if (i != j) {
                            int x1 = jokers.get(0)[0];
                            int y1 = jokers.get(0)[1];
                            int x2 = jokers.get(1)[0];
                            int y2 = jokers.get(1)[1];
                            String s1 = a[x1][y1];
                            a[x1][y1] = miss.get(i);
                            String s2 = a[x2][y2];
                            a[x2][y2] = miss.get(j);

                            List<int[]> newvalids = new ArrayList<int[]>();
                            for(int k=0;k<valids.size();k++)
                                newvalids.add(valids.get(k));
                            boolean[][] b = new boolean[n][m];
                            for(int k=x1-2;k<=x1+2;k++)
                                for(int l=y1-2;l<=y1+2;l++) {
                                    if (k >= 0 && k < n-2 && l >= 0 && l < m - 2 &&
                                        !b[k][l] && !bb[k][l] && check(k, l)) {
                                        newvalids.add(new int[]{k, l});
                                        b[k][l] = true;
                                    }
                                }
                            for(int k=x2-2;k<=x2+2;k++)
                                for(int l=y2-2;l<=y2+2;l++) {
                                    if (k >= 0 && k < n-2 && l >= 0 && l < m - 2 &&
                                        !b[k][l] && !bb[k][l] && check(k, l)) {
                                        newvalids.add(new int[]{k, l});
                                        b[k][l] = true;
                                    }
                                }
                            for(int k=0;k<newvalids.size();k++)
                                for(int l=0;l<newvalids.size();l++)
                                    if (k != l) {
                                        int px1 = newvalids.get(k)[0];
                                        int py1 = newvalids.get(k)[1];
                                        int px2 = newvalids.get(l)[0];
                                        int py2 = newvalids.get(l)[1];
                                        if (Math.max(px1, px2) > Math.min(px1 + 2, px2 + 2) ||
                                            Math.max(py1, py2) > Math.min(py1 + 2, py2 + 2)) {
                                            if (!globalfind) {
                                                globalfind = true;
                                                pos1[0] = px1;
                                                pos1[1] = py1;
                                                pos2[0] = px2;
                                                pos2[1] = py2;
                                                replace.set(0, miss.get(i));
                                                replace.set(1, miss.get(j));
                                            }
                                        }
                                    }

                            a[x1][y1] = s1;
                            a[x2][y2] = s2;
                        }
                    }
                }
            }

            if (!globalfind) {
                out.printf("No solution.");
            } else {
                out.printf("Solution exists.\n");
                if (jokers.size() == 0)
                    out.printf("There are no jokers.\n");
                else if (jokers.size() == 1) {
                    out.printf("Replace %s with %s.\n", js.get(0), replace.get(0));
                } else {
                    if (js.get(0).equals("J2")) {
                        out.printf("Replace J1 with %s and J2 with %s.\n", replace.get(1), replace.get(0));
                    } else {
                        out.printf("Replace J1 with %s and J2 with %s.\n", replace.get(0), replace.get(1));
                    }
                }
                out.printf("Put the first square to (%d, %d).\n", pos1[0] + 1, pos1[1] + 1);
                out.printf("Put the second square to (%d, %d).\n", pos2[0] + 1, pos2[1] + 1);
            }

            br.close();
            out.close();
            reader.close();
            writer.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        finally {
        }
    }


    public static void main(String[] args) {
        ProblemC f = new ProblemC();
        f.solve();
    }

    private class MyTokenizer {
        private String s;
        private int cur;

        public MyTokenizer(String s) {
            this.s = s;
            cur = 0;
        }

        public void skip() {
            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\t' || s.charAt(cur) == '\n')) {
                cur++;
            }
        }

        public double getDouble() {
            skip();
            String snum = "";
            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {
                snum += s.charAt(cur);
                cur++;
            }
            if (snum.startsWith("."))
                snum = "0" + snum;
            return Double.valueOf(snum);
        }

        public int getInteger() {
            skip();
            String snum = "";
            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {
                snum += s.charAt(cur);
                cur++;
            }
            return Integer.valueOf(snum);
        }

        public String getString() {
            skip();
            String s2 = "";
            while (cur < s.length() && (((s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) ||
                    ((s.charAt(cur) >= 'A' && s.charAt(cur) <= 'Z')) ||
                    ((s.charAt(cur) >= '0' && s.charAt(cur) <= '9')) ||
                    s.charAt(cur) == '_'
            )) {
                s2 += s.charAt(cur);
                cur++;
            }
            return s2;
        }

        public char getCurrentChar() throws Exception {
            if (cur < s.length())
                return s.charAt(cur);
            else
                throw new Exception("Current character out of string length");
        }

        public void moveNextChar() {
            if (cur < s.length())
                cur++;
        }

        public boolean isFinished() {
            return cur >= s.length();
        }
    }
}