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.*;
import java.util.*;
import java.math.*;


public class Main {
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    static char[][] a;
    static int n;
    static boolean[][][] used;
    static int[][][] p;
    static int X = -1, Y = -1, Z = -1;
    
    
    static void solve() throws Exception {
        n = nextInt();
        int x = nextInt();
        int y = nextInt();
        int z = nextInt();
        a = new char[n+1][n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = ("#" + next()).toCharArray();
        }
        used = new boolean[n+1][n+1][n+1];
        p = new int[n+1][n+1][n+1];
        bfs(x, y, z);
        if (X == -1) {
            out.println("-1");
            return;
        }
        ArrayList<Integer> res = new ArrayList<Integer>();
        x = X;
        y = Y;
        z = Z;
        while (p[x][y][z] != -1) {
            X = p[x][y][z] / 10000;
            Y = (p[x][y][z] % 10000) / 100;
            Z = p[x][y][z] % 100;
            if (x != X) {
                res.add(X);
                res.add(x);
            } else if (y != Y) {
                res.add(Y);
                res.add(y);
            } else {
                res.add(Z);
                res.add(z);
            }
            x = X;
            y = Y;
            z = Z; 
        }
        out.println(res.size() / 2);
        for (int i = res.size()-1; i >= 0; i -= 2) {
            out.println(res.get(i-1) + " " + res.get(i));
        }
    }
    
    static void bfs(int x, int y, int z) {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(x);
        q.add(y);
        q.add(z);
        p[x][y][z] = -1;
        used[x][y][z] = true;
        while (!q.isEmpty()) {
            x = q.poll();
            y = q.poll();
            z = q.poll();
            if ((x == 1 && y == 2 && z == 3) || (x == 1 && y == 3 && z == 2) || (x == 2 && y == 1 && z == 3) ||
                (x == 2 && y == 3 && z == 1) || (x == 3 && y == 1 && z == 2) || (x == 3 && y == 2 && z == 1)) {
                X = x;
                Y = y;
                Z = z;
                return;
            }
            int prev = f(x,y,z);
            for (int i = 1; i <= n; i++) {
                if (a[x][i] == a[y][z] && !used[i][y][z] && i != y && i != z) {
                    p[i][y][z] = prev;
                    q.add(i);
                    q.add(y);
                    q.add(z);
                    used[i][y][z] = true;
                }
                if (a[y][i] == a[x][z] && !used[x][i][z] && i != x && i != z) {
                    p[x][i][z] = prev;
                    q.add(x);
                    q.add(i);
                    q.add(z);
                    used[x][i][z] = true;
                }
                if (a[z][i] == a[x][y] && !used[x][y][i] && i != x && i != y) {
                    p[x][y][i] = prev;
                    q.add(x);
                    q.add(y);
                    q.add(i);
                    used[x][y][i] = true;
                }
            }
        }
    }
    
    static int f(int x, int y, int z) {
        return x*10000 + y*100 + z;
    }

    static int sqr(int x) {
        return x*x;
    }
    
    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

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

    static BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }
    
    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }
    
    static String nextLine() throws IOException {
        tok = new StringTokenizer("");
        return in.readLine();
    }

    static boolean hasNext() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null) {
                return false;
            }
            tok = new StringTokenizer(s);
        }
        return true;
    }

    public static void main(String args[]) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            //in = new BufferedReader(new FileReader("input.in"));
            //out = new PrintWriter(new FileWriter("output.out"));
            solve();
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            java.lang.System.exit(1);
        }
    }
}