Problem: You are playing the following game. There are n points on a plane. They are the vertices of a regular n-polygon. Points are labeled with integer numbers from 1 to n. Each pair of distinct points is connected by a diagonal, which is colored in one of 26 colors. Points are denoted by lowercase English letters. There are three stones positioned on three distinct vertices. All stones are the same. With one move you can move the stone to another free vertex along some diagonal. The color of this diagonal must be the same as the color of the diagonal, connecting another two stones. 

Your goal is to move stones in such way that the only vertices occupied by stones are 1, 2 and 3. You must achieve such position using minimal number of moves. Write a program which plays this game in an optimal way.

Input

In the first line there is one integer n (3 ≤ n ≤ 70) — the number of points. In the second line there are three space-separated integer from 1 to n — numbers of vertices, where stones are initially located.

Each of the following n lines contains n symbols — the matrix denoting the colors of the diagonals. Colors are denoted by lowercase English letters. The symbol j of line i denotes the color of diagonal between points i and j. Matrix is symmetric, so j-th symbol of i-th line is equal to i-th symbol of j-th line. Main diagonal is filled with '*' symbols because there is no diagonal, connecting point to itself.

Output

If there is no way to put stones on vertices 1, 2 and 3, print -1 on a single line. Otherwise, on the first line print minimal required number of moves and in the next lines print the description of each move, one move per line. To describe a move print two integers. The point from which to remove the stone, and the point to which move the stone. If there are several optimal solutions, print any of them.

Examples

Input

4
2 3 4
*aba
a*ab
ba*b
abb*


Output

1
4 1


Input

4
2 3 4
*abc
a*ab
ba*b
cbb*


Output

-1

Note

In the first example we can move stone from point 4 to point 1 because this points are connected by the diagonal of color 'a' and the diagonal connection point 2 and 3, where the other stones are located, are connected by the diagonal of the same color. After that stones will be on the points 1, 2 and 3.

Solution (in JAVA):

Solution:
// Don't place your source in a package


import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;



// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

        long Long() {
            return Long.parseLong(next());
        }

        String Str(){
            return next();
        }
    }


    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        //reading /writing file
        //Scanner sc=new Scanner(new File("input.txt"));
        //PrintWriter pr=new PrintWriter("output.txt");



        int T=1;
        for(int t=0;t<T;t++){
            int n=Int();
            int p1=Int()-1;
            int p2=Int()-1;
            int p3=Int()-1;
            char A[][]=new char[n][n];
            for(int i=0;i<n;i++){
                String s=Str();
                for(int j=0;j<n;j++){
                    A[i][j]=s.charAt(j);
                }
            }
            Solution sol=new Solution(out);
            sol.solution(A,p1,p2,p3);
        }
        out.close();

    }


    public static int[] Arr(int n){
        int A[]=new int[n];
        for(int i=0;i<n;i++)A[i]=Int();
        return A;
    }
    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}








class Solution {
    PrintWriter out;
    int INF = Integer.MAX_VALUE;
    int MOD = 1000000007;
    int mod = MOD;
    public Solution(PrintWriter out) {
        this.out = out;
    }




    public void solution(char A[][],int p1,int p2,int p3) {
        int n =A.length;
        int dis[][][]=new int[n][n][n];
        int pre[][][][]=new int[n][n][n][2];
        for(int i=0;i<dis.length;i++){
            for(int j=0;j<dis[0].length;j++){
                Arrays.fill(dis[i][j],INF);
            }
        }

        Queue<int[]>q=new LinkedList<>();
        q.add(new int[]{p1,p2,p3});
        dis[p1][p2][p3]=0;

        while(q.size()>0){
            int tuple[]=q.poll();
            int pp1=tuple[0],pp2=tuple[1],pp3=tuple[2];
            if(pp1==pp2||pp1==pp3||pp2==pp3)continue;
            //System.out.println(Arrays.toString(tuple)+"  "+dis[pp1][pp2][pp3]);
            //move pp1

            for(int next=0;next<n;next++){
                if(A[pp1][next]==A[pp2][pp3]){
                    if(dis[pp1][pp2][pp3]+1<dis[next][pp2][pp3]){
                        dis[next][pp2][pp3]=dis[pp1][pp2][pp3]+1;
                        pre[next][pp2][pp3]=new int[]{pp1,next,0};
                        q.add(new int[]{next,pp2,pp3});
                    }
                }
            }


            //move pp2
            for(int next=0;next<n;next++){
                if(A[pp2][next]==A[pp1][pp3]){
                    if(dis[pp1][pp2][pp3]+1<dis[pp1][next][pp3]){
                        dis[pp1][next][pp3]=1+dis[pp1][pp2][pp3];
                        pre[pp1][next][pp3]=new int[]{pp2,next,1};
                        q.add(new int[]{pp1,next,pp3});
                    }
                }
            }

            //move pp3
            for(int next=0;next<n;next++){
                if(A[pp3][next]==A[pp1][pp2]){
                    if(dis[pp1][pp2][pp3]+1<dis[pp1][pp2][next]){
                        dis[pp1][pp2][next]=1+dis[pp1][pp2][pp3];
                        pre[pp1][pp2][next]=new int[]{pp3,next,2};
                        q.add(new int[]{pp1,pp2,next});
                    }
                }
            }
        }

        int mn=INF;
        int pair[]=new int[]{-1,-1,-1};
        if(mn>dis[0][1][2]){
            mn=dis[0][1][2];
            pair[0]=0;
            pair[1]=1;
            pair[2]=2;
        }

        if(mn>dis[0][2][1]){
            mn=dis[0][2][1];
            pair[0]=0;
            pair[1]=2;
            pair[2]=1;
        }

        if(mn>dis[1][2][0]){
            mn=dis[1][2][0];
            pair[0]=1;
            pair[1]=2;
            pair[2]=0;
        }

        if(mn>dis[1][0][2]){
            mn=dis[1][0][2];
            pair[0]=1;
            pair[1]=0;
            pair[2]=2;
        }

        if(mn>dis[2][0][1]){
            mn=dis[2][0][1];
            pair[0]=2;
            pair[1]=0;
            pair[2]=1;
        }

        if(mn>dis[2][1][0]){
            mn=dis[2][1][0];
            pair[0]=2;
            pair[1]=1;
            pair[2]=0;
        }


        if(mn==INF){
            out.println(-1);
            return;
        }

        //System.out.println(Arrays.toString(pair)+"  "+Arrays.toString(pre[pair[0]][pair[1]][pair[2]]));

        List<int[]>res=new ArrayList<>();
        while(pair[0]!=p1||pair[1]!=p2||pair[2]!=p3){
            int p[]=pre[pair[0]][pair[1]][pair[2]];
            res.add(new int[]{p[0]+1,p[1]+1});
            if(p[2]==0){
                pair[0]=p[0];
            }

            if(p[2]==1){
                pair[1]=p[0];
            }

            if(p[2]==2){
                pair[2]=p[0];
            }
        }

        out.println(mn);
        Collections.reverse(res);
        for(int p[]:res){
            out.println(p[0]+" "+p[1]);
        }

    }


}