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 = 75;
bool visit[MAXN][MAXN][MAXN];
int n, ans[MAXN][MAXN][MAXN], p1[MAXN][MAXN][MAXN], p2[MAXN][MAXN][MAXN],
    p3[MAXN][MAXN][MAXN], fr[MAXN][MAXN][MAXN], to[MAXN][MAXN][MAXN], vf1, vf2,
    vf3, l1 = -1, l2, l3;
string s[MAXN];
void vist(int x1, int x2, int x3, int h) {
  visit[x1][x2][x3] = true;
  visit[x1][x2][x3] = true;
  visit[x2][x1][x3] = true;
  visit[x2][x3][x1] = true;
  visit[x3][x1][x1] = true;
  ans[x1][x2][x3] = h;
  ans[x1][x2][x3] = h;
  ans[x2][x1][x3] = h;
  ans[x2][x3][x1] = h;
  ans[x3][x1][x1] = h;
  return;
}
void bfs() {
  vist(vf1, vf2, vf3, 0);
  queue<pair<pair<int, int>, int>> q;
  p1[vf1][vf2][vf3] = -1;
  p3[vf1][vf2][vf3] = -1;
  p2[vf1][vf2][vf3] = -1;
  q.push({{vf1, vf2}, vf3});
  while (!q.empty()) {
    int v1 = q.front().first.first, v2 = q.front().first.second,
        v3 = q.front().second;
    if ((v1 == 0 && v2 == 1 && v3 == 2) || (v1 == 0 && v2 == 2 && v3 == 1) ||
        (v1 == 1 && v2 == 0 && v3 == 2) || (v1 == 1 && v2 == 2 && v3 == 0) ||
        (v1 == 2 && v2 == 0 && v3 == 1) || (v1 == 2 && v2 == 1 && v3 == 0)) {
      l1 = v1;
      l2 = v2;
      l3 = v3;
      return;
    }
    q.pop();
    for (int i = 0; i < n; i++) {
      if (i == v1 || i == v2 || i == v3) continue;
      if (s[v1][v2] == s[v3][i] && !visit[v1][v2][i]) {
        vist(v1, v2, i, ans[v1][v2][v3] + 1);
        p1[v1][v2][i] = v1;
        p2[v1][v2][i] = v2;
        p3[v1][v2][i] = v3;
        fr[v1][v2][i] = v3;
        to[v1][v2][i] = i;
        q.push({{v1, v2}, i});
      }
      if (s[v1][v3] == s[v2][i] && !visit[v1][i][v3]) {
        vist(v1, i, v3, ans[v1][v2][v3] + 1);
        p1[v1][i][v3] = v1;
        p2[v1][i][v3] = v2;
        p3[v1][i][v3] = v3;
        fr[v1][i][v3] = v2;
        to[v1][i][v3] = i;
        q.push({{v1, i}, v3});
      }
      if (s[v2][v3] == s[v1][i] && !visit[i][v2][v3]) {
        vist(i, v2, v3, ans[v1][v2][v3] + 1);
        p1[i][v2][v3] = v1;
        p2[i][v2][v3] = v2;
        p3[i][v2][v3] = v3;
        fr[i][v2][v3] = v1;
        to[i][v2][v3] = i;
        q.push({{i, v2}, v3});
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> vf1 >> vf2 >> vf3;
  vf1--, vf2--, vf3--;
  for (int i = 0; i < n; i++) cin >> s[i];
  bfs();
  if (l1 == -1) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<int, int>> a;
  int v1 = l1, v2 = l2, v3 = l3, vv1, vv2, vv3;
  while (p1[v1][v2][v3] != -1) {
    a.push_back({fr[v1][v2][v3], to[v1][v2][v3]});
    vv1 = p1[v1][v2][v3];
    vv2 = p2[v1][v2][v3];
    vv3 = p3[v1][v2][v3];
    v1 = vv1;
    v2 = vv2;
    v3 = vv3;
  }
  cout << a.size() << endl;
  while (!a.empty()) {
    cout << a.back().first + 1 << " " << a.back().second + 1 << endl;
    a.pop_back();
  }
  return 0;
}