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 CPP):

Solution:
#include <bits/stdc++.h>
bool is_checked[70][70][70];
int states[60000];
int parent[60000];
int next[60000];
int front = 0;
int back = 0;
char map[71][71];
int n;
inline bool checked(int stones[3]);
inline bool checked(int state);
inline void state2stones(int state, int stones[3]);
inline int stones2state(int stones[3]);
inline void set_checked(int stones[3]);
bool find_it(int stones[3]);
int main() {
  scanf("%d", &n);
  int stones[3];
  for (int i = 0; i < 3; i++) {
    scanf("%d", &stones[i]);
    stones[i]--;
  }
  for (int i = 0; i < n; i++) {
    gets(map[i]);
    if (strlen(map[i]) == 0) {
      i--;
    }
  }
  bool found = find_it(stones);
  if (!found) {
    printf("-1");
  } else {
    int steps = 0;
    int s = back - 1;
    while (parent[s] != -1) {
      next[parent[s]] = s;
      s = parent[s];
      steps++;
    }
    printf("%d\n", steps);
    s = next[0];
    int stones_last[3];
    state2stones(states[0], stones_last);
    for (int i = 0; i < steps; i++) {
      state2stones(states[s], stones);
      for (int j = 0; j < 3; j++) {
        if (stones[j] != stones_last[j]) {
          printf("%d %d\n", stones_last[j] + 1, stones[j] + 1);
          stones_last[j] = stones[j];
          break;
        }
      }
      s = next[s];
    }
  }
  return 0;
}
bool find_it(int stones[3]) {
  states[back] = stones2state(stones);
  parent[back++] = -1;
  if (stones[0] >= 0 && stones[0] <= 2 && stones[1] >= 0 && stones[1] <= 2 &&
      stones[2] >= 0 && stones[2] <= 2) {
    return true;
  }
  while (front < back) {
    int state = states[front];
    state2stones(state, stones);
    int stones_temp[3];
    stones_temp[1] = stones[1];
    stones_temp[2] = stones[2];
    for (int i = 0; i < n; i++) {
      if (i == stones[0] || i == stones[1] || i == stones[2]) {
        continue;
      }
      if (map[i][stones[0]] == map[stones[1]][stones[2]]) {
        stones_temp[0] = i;
        if (!checked(stones_temp)) {
          states[back] = stones2state(stones_temp);
          parent[back++] = front;
          set_checked(stones_temp);
          if (stones_temp[0] >= 0 && stones_temp[0] <= 2 &&
              stones_temp[1] >= 0 && stones_temp[1] <= 2 &&
              stones_temp[2] >= 0 && stones_temp[2] <= 2) {
            return true;
          }
        }
      }
    }
    stones_temp[0] = stones[0];
    stones_temp[2] = stones[2];
    for (int i = 0; i < n; i++) {
      if (i == stones[0] || i == stones[1] || i == stones[2]) {
        continue;
      }
      if (map[i][stones[1]] == map[stones[0]][stones[2]]) {
        stones_temp[1] = i;
        if (!checked(stones_temp)) {
          states[back] = stones2state(stones_temp);
          parent[back++] = front;
          set_checked(stones_temp);
          if (stones_temp[0] >= 0 && stones_temp[0] <= 2 &&
              stones_temp[1] >= 0 && stones_temp[1] <= 2 &&
              stones_temp[2] >= 0 && stones_temp[2] <= 2) {
            return true;
          }
        }
      }
    }
    stones_temp[0] = stones[0];
    stones_temp[1] = stones[1];
    for (int i = 0; i < n; i++) {
      if (i == stones[0] || i == stones[1] || i == stones[2]) {
        continue;
      }
      if (map[i][stones[2]] == map[stones[0]][stones[1]]) {
        stones_temp[2] = i;
        if (!checked(stones_temp)) {
          states[back] = stones2state(stones_temp);
          parent[back++] = front;
          set_checked(stones_temp);
          if (stones_temp[0] >= 0 && stones_temp[0] <= 2 &&
              stones_temp[1] >= 0 && stones_temp[1] <= 2 &&
              stones_temp[2] >= 0 && stones_temp[2] <= 2) {
            return true;
          }
        }
      }
    }
    front++;
  }
  return false;
}
inline bool checked(int stones[3]) {
  return (
      (stones[0] < stones[1])
          ? (stones[1] < stones[2])
                ? is_checked[stones[0]][stones[1]][stones[2]]
            : (stones[2] < stones[0])
                ? is_checked[stones[2]][stones[0]][stones[1]]
                : is_checked[stones[0]][stones[2]][stones[1]]
      : (stones[2] < stones[1]) ? is_checked[stones[2]][stones[1]][stones[0]]
      : (stones[0] < stones[2]) ? is_checked[stones[1]][stones[0]][stones[2]]
                                : is_checked[stones[1]][stones[2]][stones[0]]);
}
inline bool checked(int state) {
  int stones[3];
  state2stones(state, stones);
  return checked(stones);
}
inline void set_checked(int stones[3]) {
  ((stones[0] < stones[1])
       ? (stones[1] < stones[2])   ? is_checked[stones[0]][stones[1]][stones[2]]
         : (stones[2] < stones[0]) ? is_checked[stones[2]][stones[0]][stones[1]]
                                   : is_checked[stones[0]][stones[2]][stones[1]]
   : (stones[2] < stones[1]) ? is_checked[stones[2]][stones[1]][stones[0]]
   : (stones[0] < stones[2]) ? is_checked[stones[1]][stones[0]][stones[2]]
                             : is_checked[stones[1]][stones[2]][stones[0]]) =
      true;
}
inline void state2stones(int state, int stones[3]) {
  stones[0] = state & 0x000000FF;
  stones[1] = (state >> 8) & 0x000000FF;
  stones[2] = (state >> 16) & 0x000000FF;
}
inline int stones2state(int stones[3]) {
  return ((stones[2] & 0x000000FF) << 16) | ((stones[1] & 0x000000FF) << 8) |
         (stones[0] & 0x000000FF);
}