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:
/**
 * Created by IntelliJ IDEA.
 * User: aircube
 * Date: 31.03.11
 * Time: 23:46
 * To change this template use File | Settings | File Templates.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;

public class taskD {


    class Card {
        int value ;
        int suite ;

        Card(String input) {
            this.value = getValue(input);
            this.suite = getSuite(input);
        }

        Card(int value, int suite) {
            this.value = value;
            this.suite = suite;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Card card = (Card) o;

            if (suite != card.suite) return false;
            if (value != card.value) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = value;
            result = 31 * result + suite;
            return result;
        }

        @Override
        public String toString() {
            return "Card{" +
                    "value=" + value +
                    ", suite=" + suite +
                    '}';
        }
    }
    int getValue(String input) {
        char ch = input.charAt(0);
        char ch0 = input.charAt(1);
        if (ch >= '2' && ch <= '9') return ch - '0';
        //«T», «J», «Q», «K» и «A»
        if (ch == 'T') return 10;
        if (ch == 'J' && (ch0 == 'C' || ch0 == 'D' || ch0 == 'H' || ch0 == 'S')) return 11;
        if (ch == 'Q') return 12;
        if (ch == 'K') return 13;
        if (ch == 'A') return 14;
        return 15;
    }
    int getSuite(String input) {
        char ch = input.charAt(0);
        char ch0 = input.charAt(1);
        //(ch0 == 'C' || ch0 == 'D' || ch0 == 'H' || ch0 == 'S')) return 11;
        if (ch0 == 'C') return 0;
        if (ch0 == 'D') return 1;
        if (ch0 == 'H') return 2;
        if (ch0 == 'S') return 3;
        if (ch0 == '1') return 4;
        if (ch0 == '2') return 5;
        throw new RuntimeException();
    }
    String cardToString(Card card) {
        String ans = "";
        if (card.value >= 2 && card.value <= 9) {
            ans += Integer.toString(card.value);
        } else if (card.value == 10) {
            ans += "T";
        } else if (card.value == 11) {
            ans += "J";
        } else if (card.value == 12) {
            ans += "Q";
        } else if (card.value == 13) {
            ans += "K";
        } else if (card.value == 14) {
            ans += "A";
        } else {
            throw new RuntimeException();
        }
        ans += toSuite(card.suite);
        return ans ;
    }

    private String toSuite(int suite) {
        char s[] = new char[] {'C', 'D', 'H', 'S'};
        return Character.toString(s[suite]);
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        Card table[][] = new Card[n][m];
        Set<Card> set = new HashSet<Card> ();

        Vector<Integer> x = new Vector<Integer> () ;
        Vector<Integer> y = new Vector<Integer>() ;
        Vector<Integer> num = new Vector<Integer> () ;
        for (int i = 0; i < n; ++i) {
            for (int j =0 ; j < m; ++j) {
                table[i][j] = new Card(nextToken());
                set.add(table[i][j]);
                if (table[i][j].value == 15) {
                    x.add(j);
                    y.add(i);
                    num.add(table[i][j].suite == 4 ? 1 : 2);
                }
            }
        }

        if (x.size() == 0) {
            int a[] = new int[4];
            if (goodTable(table, a)) {
                out.println("Solution exists.");
                out.println("There are no jokers.");
                out.println("Put the first square to (" + (a[1] + 1) + ", " + (a[0] + 1) + ").");
                out.println("Put the second square to ("+(a[3]+1)+", "+(a[2]+1)+").");
            } else {
                out.println("No solution.");
            }
        } else {
            if (x.size() == 1) {
                int a[] = new int[4];
                for (int val = 2; val <= 14; ++val) {
                    for (int suite = 0; suite <= 3; ++suite) {
                        if (!set.contains(new Card(val, suite))) {
                            table[y.get(0)][x.get(0)] = new Card(val, suite);
                            if (goodTable(table, a)) {
                                out.println("Solution exists.");
                                out.println("Replace J" + (num.get(0)) + " with " + cardToString(new Card(val, suite)) + ".");
                                out.println("Put the first square to (" + (a[1] + 1) + ", " + (a[0] + 1) + ").");
                                out.println("Put the second square to ("+(a[3]+1)+", "+(a[2]+1)+").");
                                return;
                            }
                        }
                    }
                }
                out.print("No solution.");
            } else {
                int a[] = new int[4];
                for (int val = 2; val <= 14; ++val) {
                    for (int suite = 0; suite <= 3; ++suite) {
                        if (!set.contains(new Card(val, suite))) {
                            table[y.get(0)][x.get(0)] = new Card(val, suite);
                            for (int val0 = 2; val0 <= 14; val0 ++) {
                                for (int suite0 = 0; suite0 <= 3; ++suite0) {
                                    if (!set.contains(new Card(val0, suite0)) && !(new Card(val0, suite0)).equals(table[y.get(0)][x.get(0)])){
                                        table[y.get(1)][x.get(1)] = new Card(val0, suite0);
                                        if (goodTable(table, a)) {
                                            out.println("Solution exists.");
                                            Card card0 = table[y.get(0)][x.get(0)];
                                            Card card1 = table[y.get(1)][x.get(1)];
                                            //Replace J1 with x and J2 with y.
                                            out.println("Replace J1 with " + (cardToString((num.get(0)==1?card0:card1))) + " and J2 with " + (cardToString((num.get(0)==2?card0:card1))) + ".");
                                            out.println("Put the first square to (" + (a[1] + 1) + ", " + (a[0] + 1) + ").");
                                            out.println("Put the second square to ("+(a[3]+1)+", "+(a[2]+1)+").");
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                out.print("No solution.");
            }
        }



    }
    class Point {
        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Point point = (Point) o;

            if (x != point.x) return false;
            if (y != point.y) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }
    }
    boolean goodTable(Card[][] table, int [] positions) {
        boolean ok = false;
        for (int Y = 0; Y < table.length - 2; ++Y) {
            for (int X = 0; X < table[0].length - 2; ++X) {
                Set<Point> busy = new HashSet<Point> () ;
                for (int dx = 0; dx < 3; ++dx) {
                    for (int dy = 0; dy < 3; ++dy) {
                        busy.add(new Point(dx + X, dy + Y));
                    }
                }
                for(int U = 0 ; U < table.length - 2 ; ++U)
                    for (int V = 0 ; V < table[0].length - 2; ++V) {
                        boolean nbusy = true;
                        for(int dx = 0; dx < 3; ++dx) {
                            for (int dy = 0; dy < 3; ++dy) {
                                if (busy.contains(new Point(dx + V, dy + U))) {
                                    nbusy = false;
                                }
                            }
                        }
                        if (!nbusy) continue;
                        if (goodSquare(X, Y, table) && goodSquare(V, U, table)) {
                            positions[0] = X;
                            positions[1] = Y;
                            positions[2] = V;
                            positions[3] = U;
                            return true;
                        }
                    }
            }
        }
        return false;
    }
    boolean goodSquare(int X, int Y, Card[][] table) {
        Set<Integer> suites = new HashSet<Integer> () ;
        Set<Integer> values = new HashSet<Integer> () ;
        for (int dx = 0; dx < 3; ++dx) {
            for (int dy = 0; dy < 3; ++dy) {
                suites.add(table[Y + dy][X + dx].suite);
                values.add(table[Y + dy][X + dx].value);
            }
        }
        return suites.size() == 1 || values.size() == 9;
    }
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;

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

    void run() throws IOException {
        /*out = new PrintWriter("input.txt");
        out.println(100000);
        for (int i =0 ; i < 100000; ++i) {
            out.print("0 ");
        }
        out.close();*/
        br = new BufferedReader(new InputStreamReader(System.in));
        //br = new BufferedReader(new FileReader("input.txt"));
        st = null;
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}