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.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Stack;
import java.util.StringTokenizer;

public class GameWithPoints {
    static class State {
        int a, b, c, cost;
        State parent;

        public State(int aa, int bb, int cc, int co, State pp) {
            a = aa;
            b = bb;
            c = cc;
            cost = co;
            parent = pp;
        }
    }
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        InputReader r = new InputReader(System.in);
        int n = r.nextInt();
        int a = r.nextInt() - 1;
        int b = r.nextInt() - 1;
        int c = r.nextInt() - 1;
        char[][] adj = new char[n][n];
        for (int i = 0; i < adj.length; i++) {
            adj[i] = r.next().toCharArray();
        }
        LinkedList<State> q = new LinkedList<State>();
        int[] newState = { a, b, c };
        Arrays.sort(newState);
        q.add(new State(newState[0], newState[1], newState[2], 0, null));
        boolean[][][] vis = new boolean[n][n][n];
        vis[a][b][c] = true;
        while (!q.isEmpty()) {
            State front = q.remove();
            if (front.a == 0 && front.b == 1 && front.c == 2) {
                out.println(front.cost);
                getPath(front);
                out.close();
                return;
            }
            for (int j = 0; j < n; j++) {
                if (adj[front.a][j] == adj[front.b][front.c]) {
                    newState[0] = j;
                    newState[1] = front.b;
                    newState[2] = front.c;
                    Arrays.sort(newState);
                    boolean can = newState[0] != newState[1] && newState[1] != newState[2];
                    if (can && !vis[newState[0]][newState[1]][newState[2]]) {
                        vis[newState[0]][newState[1]][newState[2]] = true;
                        q.add(new State(newState[0], newState[1], newState[2], front.cost + 1, front));
                    }
                }
                if (adj[front.b][j] == adj[front.a][front.c]) {
                    newState[0] = j;
                    newState[1] = front.a;
                    newState[2] = front.c;
                    Arrays.sort(newState);
                    boolean can = newState[0] != newState[1] && newState[1] != newState[2];
                    if (can && !vis[newState[0]][newState[1]][newState[2]]) {
                        vis[newState[0]][newState[1]][newState[2]] = true;
                        q.add(new State(newState[0], newState[1], newState[2], front.cost + 1, front));
                    }
                }
                if (adj[front.c][j] == adj[front.b][front.a]) {
                    newState[0] = j;
                    newState[1] = front.b;
                    newState[2] = front.a;
                    Arrays.sort(newState);
                    boolean can = newState[0] != newState[1] && newState[1] != newState[2];
                    if (can && !vis[newState[0]][newState[1]][newState[2]]) {
                        vis[newState[0]][newState[1]][newState[2]] = true;
                        q.add(new State(newState[0], newState[1], newState[2], front.cost + 1, front));
                    }
                }
            }
        }
        out.println(-1);
        out.close();
    }

    private static void getPath(State front) {
        Stack<State> stack = new Stack<State>();
        while (front != null) {
            stack.push(front);
            front = front.parent;
        }
        State from = stack.pop();
        while (!stack.isEmpty()) {
            State to = stack.pop();
            int[] a = {from.a, from.b, from.c};
            int[] b = {to.a, to.b, to.c};
            for(int x: a)
                if (!contains(b,x))
                    out.print((x+1));
            for(int x: b)
                if (!contains(a,x))
                    out.println(" "+(x+1));
            from = to;
        }
        
    }

    private static boolean contains(int[] b, int x) {
        for(int k: b)
            if (x == k)
                return true;
        return false;
    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public InputReader(FileReader stream) {
            reader = new BufferedReader(stream);
            tokenizer = null;
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

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