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;
constexpr int N = 70 + 10;
constexpr int M = 1000 + 10;
constexpr int INF = 1e9;
struct State {
  int a1, a2, a3;
  State(int _a, int _b, int _c) {
    int arr[3] = {_a, _b, _c};
    sort(arr, arr + 3);
    a1 = arr[0];
    a2 = arr[1];
    a3 = arr[2];
  }
} now(0, 0, 0), cur(0, 0, 0);
long long n, a, b, c, dist[N][N][N];
char node[N][N];
queue<State> q;
vector<pair<int, int>> ans;
void make(State nw) {
  int d = dist[nw.a1][nw.a2][nw.a3];
  char f = node[nw.a2][nw.a3];
  for (int i = 1; i <= n; i++) {
    State x = State(i, nw.a2, nw.a3);
    if (i != nw.a1 && i != nw.a2 && i != nw.a3 && node[nw.a1][i] == f &&
        dist[x.a1][x.a2][x.a3] == d - 1) {
      make(x);
      ans.push_back({i, nw.a1});
      return;
    }
  }
  f = node[nw.a1][nw.a3];
  for (int i = 1; i <= n; i++) {
    State x = State(i, nw.a1, nw.a3);
    if (i != nw.a1 && i != nw.a2 && i != nw.a3 && node[nw.a2][i] == f &&
        dist[x.a1][x.a2][x.a3] == d - 1) {
      make(x);
      ans.push_back({i, nw.a2});
      return;
    }
  }
  f = node[nw.a1][nw.a2];
  for (int i = 1; i <= n; i++) {
    State x = State(i, nw.a1, nw.a2);
    if (i != nw.a1 && i != nw.a2 && i != nw.a3 && node[nw.a3][i] == f &&
        dist[x.a1][x.a2][x.a3] == d - 1) {
      make(x);
      ans.push_back({i, nw.a3});
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> b >> c;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> node[i][j];
  now = State(a, b, c);
  q.push(now);
  memset(dist, 63, sizeof(dist));
  dist[now.a1][now.a2][now.a3] = 0;
  while (!q.empty()) {
    now = q.front();
    q.pop();
    char ty;
    int dst = dist[now.a1][now.a2][now.a3];
    ty = node[now.a2][now.a3];
    for (int i = 1; i <= n; i++) {
      if (i != now.a1 && i != now.a2 && i != now.a3 && node[now.a1][i] == ty) {
        cur = State(now.a2, now.a3, i);
        if (dist[cur.a1][cur.a2][cur.a3] > 1e7) {
          dist[cur.a1][cur.a2][cur.a3] = dst + 1;
          q.push(cur);
        }
      }
    }
    ty = node[now.a1][now.a3];
    for (int i = 1; i <= n; i++) {
      if (i != now.a1 && i != now.a2 && i != now.a3 && node[now.a2][i] == ty) {
        cur = State(now.a1, now.a3, i);
        if (dist[cur.a1][cur.a2][cur.a3] > 1e7) {
          dist[cur.a1][cur.a2][cur.a3] = dst + 1;
          q.push(cur);
        }
      }
    }
    ty = node[now.a1][now.a2];
    for (int i = 1; i <= n; i++) {
      if (i != now.a1 && i != now.a2 && i != now.a3 && node[now.a3][i] == ty) {
        cur = State(now.a1, now.a2, i);
        if (dist[cur.a1][cur.a2][cur.a3] > 1e7) {
          dist[cur.a1][cur.a2][cur.a3] = dst + 1;
          q.push(cur);
        }
      }
    }
  }
  if (dist[1][2][3] > 1e7)
    cout << -1 << '\n';
  else {
    cout << dist[1][2][3] << '\n';
    cur = State(1, 2, 3);
    make(cur);
    for (auto i : ans) cout << i.first << ' ' << i.second << '\n';
  }
  return 0;
}