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;
const int maxn = 70;
const int inf = 0x7f7f7f7f;
class State {
 public:
  int a;
  int b;
  int c;
  State(void);
  State(int, int, int);
};
State::State(void) : a(0), b(0), c(0) {}
State::State(int a, int b, int c) : a(a), b(b), c(c) {}
int n;
int inita, initb, initc;
char clr[maxn][maxn + 1];
int d[maxn][maxn][maxn];
State p[maxn][maxn][maxn];
int E[maxn][26][maxn];
int Esz[maxn][26];
State que[maxn * maxn * maxn];
int qh, qt;
pair<int, int> stk[maxn * maxn * maxn];
int sh;
bool flg[2][3];
inline void validate(int& a, int& b, int& c) {
  if (a > b) swap(a, b);
  if (a > c) swap(a, c);
  if (b > c) swap(b, c);
}
int main(void) {
  int i, j, k;
  State cur, tgt, tmp;
  int curd, c, a, b;
  scanf("%d", &n);
  scanf("%d %d %d", &inita, &initb, &initc);
  for (i = 0; i < n; ++i) scanf("%s", clr[i]);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      if (i == j) continue;
      c = clr[i][j] - 'a';
      E[i][c][Esz[i][c]] = j;
      ++Esz[i][c];
    }
  }
  --inita;
  --initb;
  --initc;
  memset(d, inf, sizeof(d));
  validate(inita, initb, initc);
  d[inita][initb][initc] = 0;
  qh = 0;
  qt = 1;
  que[qh] = State(inita, initb, initc);
  for (; qh < qt && d[0][1][2] == inf; ++qh) {
    cur = que[qh];
    curd = d[cur.a][cur.b][cur.c];
    for (k = 0; k < 3; ++k) {
      if (k == 1)
        swap(cur.a, cur.b);
      else if (k == 2)
        swap(cur.a, cur.c);
      c = clr[cur.b][cur.c] - 'a';
      for (i = 0; i < Esz[cur.a][c]; ++i) {
        tgt = cur;
        tgt.a = E[cur.a][c][i];
        if (tgt.a == cur.b || tgt.a == cur.c) continue;
        validate(tgt.a, tgt.b, tgt.c);
        if (d[tgt.a][tgt.b][tgt.c] == inf) {
          d[tgt.a][tgt.b][tgt.c] = curd + 1;
          que[qt] = tgt;
          ++qt;
          tmp = cur;
          validate(tmp.a, tmp.b, tmp.c);
          p[tgt.a][tgt.b][tgt.c] = tmp;
          if (d[0][1][2] < inf) break;
        }
      }
      if (d[0][1][2] < inf) break;
    }
  }
  if (d[0][1][2] == inf)
    printf("-1\n");
  else {
    printf("%d\n", d[0][1][2]);
    curd = d[0][1][2];
    for (cur = State(0, 1, 2); curd > 0; --curd) {
      memset(flg, false, sizeof(flg));
      for (i = 0; i < 3; ++i) {
        if (i == 0)
          a = cur.a;
        else if (i == 1)
          a = cur.b;
        else
          a = cur.c;
        for (j = 0; j < 3; ++j) {
          if (j == 0)
            b = p[cur.a][cur.b][cur.c].a;
          else if (j == 1)
            b = p[cur.a][cur.b][cur.c].b;
          else
            b = p[cur.a][cur.b][cur.c].c;
          if (a == b) {
            flg[0][i] = true;
            flg[1][j] = true;
            break;
          }
        }
      }
      for (i = 0; i < 3; ++i) {
        if (!flg[0][i]) break;
      }
      if (i == 0)
        a = cur.a;
      else if (i == 1)
        a = cur.b;
      else
        a = cur.c;
      for (j = 0; j < 3; ++j) {
        if (!flg[1][j]) break;
      }
      if (j == 0)
        b = p[cur.a][cur.b][cur.c].a;
      else if (j == 1)
        b = p[cur.a][cur.b][cur.c].b;
      else
        b = p[cur.a][cur.b][cur.c].c;
      stk[sh] = pair<int, int>(b, a);
      ++sh;
      cur = p[cur.a][cur.b][cur.c];
    }
    for (; sh > 0; --sh)
      printf("%d %d\n", stk[sh - 1].first + 1, stk[sh - 1].second + 1);
  }
  return 0;
}