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 inf = 1e9 + 7, maxn = 100;
bool visited[maxn][maxn][maxn];
int n, dp[maxn][maxn][maxn];
pair<int, pair<int, int> > par[maxn][maxn][maxn];
pair<int, int> ans[maxn][maxn][maxn];
vector<pair<int, int> > v;
string s[maxn];
queue<pair<int, pair<int, int> > > q;
void f(int a, int b, int c) {
  dp[a][b][c] = 0;
  dp[a][c][b] = 0;
  dp[b][c][a] = 0;
  dp[b][a][c] = 0;
  dp[c][a][b] = 0;
  dp[c][b][a] = 0;
  q.push({a, {b, c}});
  q.push({a, {c, b}});
  q.push({b, {a, c}});
  q.push({b, {c, a}});
  q.push({c, {a, b}});
  q.push({c, {b, a}});
  visited[a][b][c] = 1;
  visited[a][c][b] = 1;
  visited[b][a][c] = 1;
  visited[b][c][a] = 1;
  visited[c][a][b] = 1;
  visited[c][b][a] = 1;
}
void bfs(int a, int b, int c) {
  visited[a][b][c] = 1;
  memset(dp, 63, sizeof dp);
  f(a, b, c);
  while (!q.empty()) {
    pair<int, pair<int, int> > v = q.front();
    q.pop();
    a = v.first;
    b = v.second.first;
    c = v.second.second;
    for (int i = 1; i <= n; i++) {
      if (i == a || i == b || i == c) continue;
      if (s[a][i] == s[b][c]) {
        if (!visited[i][b][c]) {
          dp[i][b][c] = dp[a][b][c] + 1;
          visited[i][b][c] = 1;
          par[i][b][c] = {a, {b, c}};
          ans[i][b][c] = {a, i};
          q.push({i, {b, c}});
        }
        if (!visited[i][c][b]) {
          dp[i][c][b] = dp[a][b][c] + 1;
          visited[i][c][b] = 1;
          par[i][c][b] = {a, {b, c}};
          ans[i][c][b] = {a, i};
          q.push({i, {c, b}});
        }
        if (!visited[b][i][c]) {
          dp[b][i][c] = dp[a][b][c] + 1;
          visited[b][i][c] = 1;
          par[b][i][c] = {a, {b, c}};
          ans[b][i][c] = {a, i};
          q.push({b, {i, c}});
        }
        if (!visited[b][c][i]) {
          dp[b][c][i] = dp[a][b][c] + 1;
          visited[b][c][i] = 1;
          par[b][c][i] = {a, {b, c}};
          ans[b][c][i] = {a, i};
          q.push({b, {c, i}});
        }
        if (!visited[c][i][b]) {
          dp[c][i][b] = dp[a][b][c] + 1;
          visited[c][i][b] = 1;
          par[c][i][b] = {a, {b, c}};
          ans[c][i][b] = {a, i};
          q.push({c, {i, b}});
        }
        if (!visited[c][b][i]) {
          dp[c][b][i] = dp[a][b][c] + 1;
          visited[c][b][i] = 1;
          par[c][b][i] = {a, {b, c}};
          ans[c][b][i] = {a, i};
          q.push({c, {b, i}});
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int a1, a2, a3;
  cin >> n >> a1 >> a2 >> a3;
  for (int i = 1; i <= n; i++) {
    string k;
    cin >> k;
    s[i] = '+' + k;
  }
  bfs(a1, a2, a3);
  if (dp[1][2][3] >= inf) dp[1][2][3] = -1;
  cout << dp[1][2][3] << endl;
  a1 = 1;
  a2 = 2;
  a3 = 3;
  while (par[a1][a2][a3].first) {
    v.push_back({ans[a1][a2][a3].first, ans[a1][a2][a3].second});
    int a = par[a1][a2][a3].first;
    int b = par[a1][a2][a3].second.first;
    int c = par[a1][a2][a3].second.second;
    a1 = a;
    a2 = b;
    a3 = c;
  }
  for (int i = v.size() - 1; i >= 0; i--)
    cout << v[i].first << " " << v[i].second << endl;
}