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>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 7e1 + 30, mod = 1e9 + 7, inf = 2e5;
const long double eps = 0.0001;
string s[N];
int dist[N][N][N], n;
pair<pair<int, int>, int> p[N][N][N];
void bfs(int x, int y, int z) {
  dist[x][y][z] = 1;
  queue<pair<pair<int, int>, int> > q;
  q.push({{x, y}, z});
  p[x][y][z] = {{-1, -1}, -1};
  while (!q.empty()) {
    auto v = q.front();
    int a = v.first.first, b = v.first.second, c = v.second;
    q.pop();
    for (int i = 0; i < n; i++) {
      if (i != b && i != c && !dist[i][b][c] && s[a][i] == s[b][c]) {
        dist[i][b][c] = dist[a][b][c] + 1;
        p[i][b][c] = {{a, b}, c};
        q.push({{i, b}, c});
      }
      if (i != a && i != c && !dist[a][i][c] && s[a][c] == s[b][i]) {
        dist[a][i][c] = dist[a][b][c] + 1;
        q.push({{a, i}, c});
        p[a][i][c] = {{a, b}, c};
      }
      if (i != b && i != a && !dist[a][b][i] && s[c][i] == s[b][a]) {
        dist[a][b][i] = dist[a][b][c] + 1;
        q.push({{a, b}, i});
        p[a][b][i] = {{a, b}, c};
      }
    }
  }
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int b, a, c;
  cin >> n >> a >> b >> c;
  a--;
  b--;
  c--;
  for (int i = 0; i < n; i++) cin >> s[i];
  bfs(a, b, c);
  if (max(dist[0][1][2],
          max(dist[0][2][1],
              max(dist[1][0][2],
                  max(dist[1][2][0], max(dist[2][0][1], dist[2][1][0]))))) ==
      0) {
    cout << -1;
    return 0;
  }
  int i, j, k, mi = 1e8;
  for (int x = 0; x < 3; x++) {
    for (int y = 0; y < 3; y++) {
      for (int z = 0; z < 3; z++) {
        if (x != y && y != z && z != x && dist[x][y][z] < mi && dist[x][y][z]) {
          mi = dist[x][y][z];
          i = x;
          j = y;
          k = z;
        }
      }
    }
  }
  cout << mi - 1 << '\n';
  stack<pair<int, int> > st;
  while (p[i][j][k].first.first != -1) {
    if (p[i][j][k].first.first != i) {
      st.push({p[i][j][k].first.first, i});
      i = p[i][j][k].first.first;
    } else {
      if (p[i][j][k].first.second != j) {
        st.push({p[i][j][k].first.second, j});
        j = p[i][j][k].first.second;
      } else {
        st.push({p[i][j][k].second, k});
        k = p[i][j][k].second;
      }
    }
  }
  while (!st.empty()) {
    cout << st.top().first + 1 << ' ' << st.top().second + 1 << '\n';
    st.pop();
  }
  return 0;
}