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:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;

public class D {
    
    static void fill(boolean[][][] in, boolean v) {
        for (int i=0; i<in.length; i++) {
            for (int j=0; j<in[i].length; j++) {
                Arrays.fill(in[i][j], v);
            }
        }
    }

    static void fill(int[][][] in, int v) {
        for (int i=0; i<in.length; i++) {
            for (int j=0; j<in[i].length; j++) {
                Arrays.fill(in[i][j], v);
            }
        }
    }
    
    static void fill_path(int[][][] fp, int v1, int v2, int v3, int[] path) {
        int cnt=0;
        int[] v=new int[3];
        fill(v,v1,v2,v3);
        
        int p=fp[v[0]][v[1]][v[2]];
        while(p>0) {
            int pv=(p>>8);
            int cv=(byte)p;
            
            path[cnt++]=p;
            if(cv==v1) {
                v1=pv;
            } else if(cv==v2) {
                v2=pv;
            } else {
                v3=pv;
            }
            
            fill(v,v1,v2,v3);
            p=fp[v[0]][v[1]][v[2]];
        }
    }
    
    static void fill(int[] v, int v1, int v2, int v3) {
        v[0]=v1; v[1]=v2; v[2]=v3;
        Arrays.sort(v);
    }
    
    static int compute(int n, int v1, int v2, int v3, String[] e, int[] path) {
        int[] v=new int[3];
        
        fill(v,v1,v2,v3);
        if(v[0]==0&&v[1]==1&&v[2]==2) {
            return 0;
        }
        
        boolean[][][] 
                fc=new boolean[n][n][n], 
                fn=new boolean[n][n][n];
        int[][][] fp=new int[n][n][n];
        
        fill(fc, false);
        fc[v[0]][v[1]][v[2]]=true;

        fill(fp, -1);
        fp[v[0]][v[1]][v[2]]=0;
        
        boolean _continue=true;
        int moves=0;
        while(_continue) {
            moves++;
            _continue=false;
            fill(fn, false);
            for (int i=0; i<n; i++) {
                for (int j=i+1; j<n; j++) {
                    for (int k=j+1; k<n; k++) {
                        if(fc[i][j][k]) {
                            for (int l=0; l<n; l++) {
                                
                                fill(v,l,j,k);
                                if(l!=j&&l!=k&&e[i].charAt(l)==e[j].charAt(k)&&fp[v[0]][v[1]][v[2]]<0) {
                                    _continue=true;
                                    fn[v[0]][v[1]][v[2]]=true;
                                    fp[v[0]][v[1]][v[2]]=(i<<8)+l;
                                    if(v[0]==0&&v[1]==1&&v[2]==2) {
                                        fill_path(fp,v[0],v[1],v[2],path);
                                        return moves;
                                    }
                                }

                                fill(v,i,l,k);
                                if(l!=i&&l!=k&&e[j].charAt(l)==e[i].charAt(k)&&fp[v[0]][v[1]][v[2]]<0) {
                                    _continue=true;
                                    fn[v[0]][v[1]][v[2]]=true;
                                    fp[v[0]][v[1]][v[2]]=(j<<8)+l;
                                    if(v[0]==0&&v[1]==1&&v[2]==2) {
                                        fill_path(fp,v[0],v[1],v[2],path);
                                        return moves;
                                    }
                                }

                                fill(v,i,j,l);
                                if(l!=i&&l!=j&&e[k].charAt(l)==e[i].charAt(j)&&fp[v[0]][v[1]][v[2]]<0) {
                                    _continue=true;
                                    fn[v[0]][v[1]][v[2]]=true;
                                    fp[v[0]][v[1]][v[2]]=(k<<8)+l;
                                    if(v[0]==0&&v[1]==1&&v[2]==2) {
                                        fill_path(fp,v[0],v[1],v[2],path);
                                        return moves;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            
            boolean[][][] tmp=fc; fc=fn; fn=tmp;
        }
        return -1;
    }
    
    
    
    
    
    
    
    static void run_stream(InputStream ins) throws IOException {
        BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(r.readLine());
        
        String[] sv=r.readLine().split(" ");
        int v1=Integer.parseInt(sv[0])-1;
        int v2=Integer.parseInt(sv[1])-1;
        int v3=Integer.parseInt(sv[2])-1;
        
        String[] e=new String[n];
        for (int i=0; i<n; i++) {
            e[i]=r.readLine();
        }
        
        int[] path=new int[n*n*n];
        int cnt=compute(n, v1, v2, v3, e, path);
        System.out.println(cnt);
        for (int i=cnt-1; i>=0; i--) {
            System.out.println((path[i]>>8)+1+" "+((byte)path[i]+1));
        } 
    }

    public static void main(String[] args) throws IOException {
        run_stream(System.in);
    }


}