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 p=fp[v1][v2][v3];
        while(p>0) {
            int w1=p>>16;
            int w2=(byte)(p>>8);
            int w3=(byte)p;
            
            if(w1!=v1) {
                path[cnt++]=(w1<<8)+v1;
                v1=w1;
            } else if(w2!=v2) {
                path[cnt++]=(w2<<8)+v2;
                v2=w2;
            } else {
                path[cnt++]=(w3<<8)+v3;
                v3=w3;
            }
            
            p=fp[v1][v2][v3];
        }
    }
    
    static int compute(int n, int v1, int v2, int v3, String[] e, int[] path) {
        int[] vv=new int[3];
        vv[0]=v1;
        vv[1]=v2;
        vv[2]=v3;
        Arrays.sort(vv);
        if(vv[0]==0&&vv[1]==1&&vv[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[v1][v2][v3]=true;
        fc[v1][v3][v2]=true;
        fc[v2][v1][v3]=true;
        fc[v2][v3][v1]=true;
        fc[v3][v1][v2]=true;
        fc[v3][v2][v1]=true;

        fill(fp, -1);
        fp[v1][v2][v3]=0;
        fp[v1][v3][v2]=0;
        fp[v2][v1][v3]=0;
        fp[v2][v3][v1]=0;
        fp[v3][v1][v2]=0;
        fp[v3][v2][v1]=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=0; j<n; j++) {
                    for (int k=0; k<n; k++) {
                        if(fc[i][j][k]) {
                            for (int l=0; l<n; l++) {
                                if(l!=j&&l!=k&&e[i].charAt(l)==e[j].charAt(k)&&fp[l][j][k]<0) {
                                    _continue=true;
                                    fn[l][j][k]=true;
                                    fp[l][j][k]=(i<<16)+(j<<8)+k;
                                    if(l==0&&j==1&&k==2) {
                                        fill_path(fp,l,j,k,path);
                                        return moves;
                                    }
                                }
                                if(l!=i&&l!=k&&e[j].charAt(l)==e[i].charAt(k)&&fp[i][l][k]<0) {
                                    _continue=true;
                                    fn[i][l][k]=true;
                                    fp[i][l][k]=(i<<16)+(j<<8)+k;
                                    if(i==0&&l==1&&k==2) {
                                        fill_path(fp,i,l,k,path);
                                        return moves;
                                    }
                                }
                                if(l!=i&&l!=j&&e[k].charAt(l)==e[i].charAt(j)&&fp[i][j][l]<0) {
                                    _continue=true;
                                    fn[i][j][l]=true;
                                    fp[i][j][l]=(i<<16)+(j<<8)+k;
                                    if(i==0&&j==1&&l==2) {
                                        fill_path(fp,i,j,l,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);
    }


}