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.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Queue;
import java.util.LinkedList;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sheep
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    private static final int MAX_VALUE = 0x3F3F3F3F;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();

        int a = in.nextInt() - 1;
        int b = in.nextInt() - 1;
        int c = in.nextInt() - 1;

        char[][] adj = new char[n][];
        for (int i = 0; i < n; ++i) {
            adj[i] = in.next().toCharArray();
        }

        int[][][] dis = new int[n][n][n];
        long[][][] from = new long[n][n][n];
        ArrayUtils.fill(dis, MAX_VALUE);
        ArrayUtils.fill(from, -1);
        dis[a][b][c] = 0;
        dis[a][c][b] = 0;
        dis[b][a][c] = 0;
        dis[b][c][a] = 0;
        dis[c][a][b] = 0;
        dis[c][b][a] = 0;

        Queue<Integer> q = new LinkedList<Integer>();
        for (a = 0; a < n; ++a) {
            for (b = 0; b < n; ++b) {
                for (c = 0; c < n; ++c) {
                    if (dis[a][b][c] == 0) {
                        q.add(a * 10000 + b * 100 + c);
                    }
                }
            }
        }

        while (!q.isEmpty()) {
            int state = q.poll();

            a = state / 10000;
            b = state % 10000 / 100;
            c = state % 100;

            int[] states = new int[] {a, b, c};
            for (int move : states) {
                int[] others = new int[2];
                int count = 0;
                for (int other : states) {
                    if (other != move) {
                        others[count++] = other;
                    }
                }

                if (count != 2) {
                    throw new IllegalStateException();
                }

                for (int p = 0; p < n; ++p) {
                    if (p == a || p == b || p == c) continue;
                    if (adj[move][p] == adj[others[0]][others[1]]) {
                        if (dis[p][others[0]][others[1]] == MAX_VALUE) {
                            dis[p][others[0]][others[1]] = dis[a][b][c] + 1;
                            from[p][others[0]][others[1]] = state * 10000L + move * 100L + p;
                            q.add(p * 10000 + others[0] * 100 + others[1]);
                        }
                    }
                }
            }
        }

        int x = 0, y = 1, z = 2;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                for (int k = 0; k < 3; ++k) {
                    if (i != j && j != k && k != i && dis[i][j][k] < dis[x][y][z]) {
                        x = i;
                        y = j;
                        z = k;
                    }
                }
            }
        }

        if (dis[x][y][z] == MAX_VALUE) {
            out.println(-1);
            return;
        }

        int current = x * 10000 + y * 100 + z;
        ArrayList<IntPair> steps = new ArrayList<IntPair>();
        while (true) {
            int state = current;
            a = state / 10000;
            b = state % 10000 / 100;
            c = state % 100;

            if (from[a][b][c] == -1) {
                break;
            }

            int nextState = (int) (from[a][b][c] / 10000);
            steps.add(new IntPair((int) (from[a][b][c] % 10000 / 100), (int) (from[a][b][c] % 100)));
            current = nextState;
        }

        out.println(steps.size());
        for (int i = steps.size() - 1; i >= 0; --i) {
            out.println((steps.get(i).first + 1) + " " + (steps.get(i).second + 1));
        }
    }
}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

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

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

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

    }

class ArrayUtils {


    public static void fill(int[][] array, int value) {
        for (int i = 0; i < array.length; ++i) {
            Arrays.fill(array[i], value);
        }
    }

    public static void fill(int[][][] array, int value) {
        for (int i = 0; i < array.length; ++i) {
            fill(array[i], value);
        }
    }
    public static void fill(long[][] array, long value) {
        for (int i = 0; i < array.length; ++i) {
            Arrays.fill(array[i], value);
        }
    }

    public static void fill(long[][][] array, long value) {
        for (int i = 0; i < array.length; ++i) {
            fill(array[i], value);
        }
    }

    }

class IntPair extends ComparablePair<Integer, Integer> {

    public IntPair() {
        super();
    }

    public IntPair(Integer first, Integer second) {
        super(first, second);
    }
}

class ComparablePair<F extends Comparable<F>, S extends Comparable<S>>
        extends Pair<F, S> implements Comparable<ComparablePair<F, S>> {

    public ComparablePair() {
        super();
    }

    public ComparablePair(F first, S second) {
        super(first, second);
    }

    public int compareTo(ComparablePair<F, S> to) {
        if (this.first.compareTo(to.first) != 0) {
            return this.first.compareTo(to.first);
        }
        return this.second.compareTo(to.second);
    }
}

class Pair<F, S> {
    public F first;
    public S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    public Pair() {
        this(null, null);
    }

    public boolean equals(Object o) {
        Pair<F, S> to = (Pair<F, S>) o;
        return first == to.first && second == to.second;
    }

    public int hashCode() {
        int result = first != null ? first.hashCode() : 0;
        result = 31 * result + (second != null ? second.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "[" + first.toString() + " " + second.toString() + "]";
    }
}