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

public class D implements Runnable
{
    String file = "input";
    
    boolean TEST = false;
    
    String ranks = "23456789TJQKA";
    String suits = "CDHS";
    Set<String> set = new HashSet<String>();
    
    void solve() throws IOException
    {
        int rn = nextInt(), cn = nextInt();
        String[][] cs = new String[rn][cn];
        int num = 0, x1 = -1, y1 = -1, x2 = -1, y2 = -1;
        for(int i = 0; i < rn; i++) 
        {
            for(int j = 0; j < cn; j++) 
            {
                cs[i][j] = next();
                set.add(cs[i][j]);
                if(cs[i][j].equals("J1") || cs[i][j].equals("J2"))
                {
                    num++;
                    if(cs[i][j].equals("J1"))
                    {
                        x1 = i;
                        y1 = j;
                    }
                    else
                    {
                        x2 = i;
                        y2 = j;
                    }
                }
            }
        }   
        
        List<String> as = new ArrayList<String>();
        boolean ok = false;
        
        if(num == 0)
        {
            ok = calc(cs, as);
            if(ok)
            {
                out.println("Solution exists.");
                out.println("There are no jokers.");
                for(String s : as) out.println(s);
            }
        }
        else if(num == 1)
        {
            outer: for(char r : ranks.toCharArray())
                for(char s : suits.toCharArray())
                {
                    if(!set.contains("" + r + s))
                    {
                        if(x1 != -1) cs[x1][y1] = "" + r + s;
                        else cs[x2][y2] = "" + r + s;
                        as.clear();
                        ok = calc(cs, as);
                        if(ok)
                        {
                            out.println("Solution exists.");
                            out.printf("Replace J%d with %s.\n", x2 == -1 ? 1 : 2, "" + r + s);
                            for(String ss : as) out.println(ss);
                            break outer;
                        }
                    }
                }
        }
        else if(num == 2)
        {
            outer: for(char r1 : ranks.toCharArray())
                        for(char s1 : suits.toCharArray())
                            for(char r2 : ranks.toCharArray())
                                for(char s2 : suits.toCharArray())
                                {
                                    String a = "" + r1 + s1;
                                    String b = "" + r2 + s2;
                                    if(a.equals(b)) continue;
                                    if(set.contains(a) || set.contains(b)) continue;
                                    cs[x1][y1] = a;
                                    cs[x2][y2] = b;
                                    as.clear();
                                    ok = calc(cs, as);
                                    if(ok)
                                    {
                                        out.println("Solution exists.");
                                        out.printf("Replace J1 with %s and J2 with %s.\n", a, b);
                                        for(String ss : as) out.println(ss);
                                        break outer;
                                    }
                                }
        }
        
        if(!ok) out.println("No solution.");
    }
    
    boolean calc(String[][] cs, List<String> as)
    {
        int rn = cs.length;
        int cn = cs[0].length;
        for(int i = 0; i < rn; i++)
            for(int j = 0; j < cn; j++)
                for(int ii = 0; ii < rn; ii++)
                    for(int jj = 0; jj < cn; jj++)
                    {
                        if(i + 2 >= rn || j + 2 >= cn || ii + 2 >= rn || jj + 2 >= cn) continue;
                        if(!ok(i, j, ii, jj)) continue;
                        if(!sameSuit(i, j, cs) && !diffRank(i, j, cs)) continue;
                        if(!sameSuit(ii, jj, cs) && !diffRank(ii, jj, cs)) continue;
                        as.add(String.format("Put the first square to (%d, %d).", i + 1, j + 1));
                        as.add(String.format("Put the second square to (%d, %d).", ii + 1, jj + 1));
                        return true;
                    }
        return false;
    }
    
    boolean sameSuit(int x, int y, String[][] cs)
    {
        char suit = 'N';
        for(int i = x; i <= x + 2; i++)
            for(int j = y; j <= y + 2; j++)
            {
                if(suit == 'N') suit = cs[i][j].charAt(1);
                else if(suit != cs[i][j].charAt(1)) return false;
            }
        return true;
    }
    boolean diffRank(int x, int y, String[][] cs)
    {
        Set<Character> set = new HashSet<Character>();
        for(int i = x; i <= x + 2; i++)
            for(int j = y; j <= y + 2; j++)
            {
                if(set.contains(cs[i][j].charAt(0))) return false;
                set.add(cs[i][j].charAt(0));
            }
        return true;
    }   
    boolean ok(int x1, int y1, int x2, int y2)
    {
        return x1 + 2 < x2 || x2 + 2 < x1 || y1 + 2 < y2 || y2 + 2 < y1;
    }
    
    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }
    
    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }
    
    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }
    
    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
    
    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }
    
    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }
    
    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;
    
    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in")); 
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }
    
    public static void main(String[] args) throws IOException
    {
        new Thread(null, new D(), "", 1 << 20).start();
    }
    
    public void run()
    {
        try
        {
            init();
            if(TEST) 
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();        
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}