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>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
char ch[4000010];
inline string get() {
  scanf("%s", ch);
  return string(ch);
}
inline void read(int *a, int n) {
  for (int i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
template <class blank, class blank2>
inline void smin(blank &a, blank2 b) {
  a = a <= b ? a : b;
}
template <class blank, class blank2>
inline void smax(blank &a, blank2 b) {
  a = a >= b ? a : b;
}
const int maxn = 3e5 + 10;
const int maxm = 4e6 + 10;
const int maxlg = 22;
const int base = 29;
const int mod = 1e9 + 7;
const long long inf = 1e18 + 10;
const double eps = 1e-4;
const int SQ = 317;
struct state {
  int a, b, c, dist;
  state(int a, int b, int c, int dist = 0) : a(a), b(b), c(c), dist(dist) {}
  state() {}
};
int a[75][75], h, t, n;
state q[maxn * 10], v;
bool mrk[75][75][75];
int DI[75][75][75];
pair<pair<int, int>, int> pre[75][75][75];
inline bool avai(int from, int to) {
  if (from == to) return false;
  int b, c;
  if (from == v.a)
    b = v.b, c = v.c;
  else
    b = v.a, c = (from == v.b ? v.c : v.b);
  if (mrk[to][b][c] || mrk[b][c][to] || mrk[b][to][c] || mrk[to][c][b] ||
      mrk[c][to][b] || mrk[c][b][to] || to == b || to == c)
    return false;
  return (a[from][to] == a[b][c]);
}
inline void bfs() {
  mrk[q[0].a][q[0].b][q[0].c] = true;
  while (h < t) {
    v = q[h++];
    pair<pair<int, int>, int> shit = {{v.a, v.b}, v.c};
    DI[v.a][v.b][v.c] = v.dist;
    if (t + 1 >= maxn) break;
    for (int i = 0; i < n; i++) {
      if (avai(v.a, i)) {
        q[t++] = {i, v.b, v.c, v.dist + 1};
        mrk[i][v.b][v.c] = true;
        pre[i][v.b][v.c] = shit;
      }
      if (avai(v.b, i)) {
        q[t++] = {v.a, i, v.c, v.dist + 1};
        mrk[v.a][i][v.c] = true;
        pre[v.a][i][v.c] = shit;
      }
      if (avai(v.c, i)) {
        q[t++] = {v.a, v.b, i, v.dist + 1};
        mrk[v.a][v.b][i] = true;
        pre[v.a][v.b][i] = shit;
      }
    }
  }
}
inline void prnt(int a, int b, int c) {
  if (DI[a][b][c] == 0) return;
  pair<pair<int, int>, int> shit = pre[a][b][c];
  prnt(shit.first.first, shit.first.second, shit.second);
  if (a != shit.first.first) {
    cout << shit.first.first + 1 << " " << a + 1 << "\n";
  } else if (b != shit.first.second) {
    cout << shit.first.second + 1 << " " << b + 1 << "\n";
  } else {
    cout << shit.second + 1 << " " << c + 1 << "\n";
  }
}
int32_t main() {
  n = in();
  int a = in() - 1, b = in() - 1, c = in() - 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char ch;
      scanf(" %c", &ch);
      ::a[i][j] = ch - 'a';
    }
  }
  q[0] = state(a, b, c);
  t = 1;
  bfs();
  int arr[] = {0, 1, 2};
  pair<pair<int, int>, int> shit;
  int di = 1000000000;
  do {
    if (mrk[arr[0]][arr[1]][arr[2]]) {
      if (DI[arr[0]][arr[1]][arr[2]] < di) {
        di = DI[arr[0]][arr[1]][arr[2]], shit = {{arr[0], arr[1]}, arr[2]};
      }
    }
  } while (next_permutation(arr, arr + 3));
  if (di == 1000000000) out(-1);
  cout << di << "\n";
  prnt(shit.first.first, shit.first.second, shit.second);
}