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;
template <typename T>
istream& operator>>(istream& in, vector<T>& arr) {
  for (T& i : arr) {
    in >> i;
  }
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<vector<T>>& arr) {
  for (vector<T>& i : arr) {
    out << i;
  }
  out << endl;
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& arr) {
  for (T& i : arr) {
    out << i << ' ';
  }
  out << endl;
  return out;
}
int dp[71][71][71];
bool visited[71][71][71];
int previous_a[71][71][71];
int previous_b[71][71][71];
int previous_c[71][71][71];
char matrix[71][71];
int main() {
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < n + 1; j++) cin >> matrix[i][j];
  for (int i = 0; i < 71; i++)
    for (int j = 0; j < 71; j++)
      for (int k = 0; k < 71; k++) dp[i][j][k] = -1;
  visited[a][b][c] = true;
  dp[a][b][c] = 0;
  queue<int> as, bs, cs;
  as.push(a);
  bs.push(b);
  cs.push(c);
  while (!as.empty()) {
    int cur_a = as.front();
    int cur_b = bs.front();
    int cur_c = cs.front();
    as.pop();
    bs.pop();
    cs.pop();
    for (int d = 1; d <= n; d++) {
      if (d != cur_a && d != cur_b && d != cur_c) {
        if (matrix[cur_a][d] == matrix[cur_b][cur_c] &&
            !visited[d][cur_b][cur_c]) {
          visited[d][cur_b][cur_c] = true;
          dp[d][cur_b][cur_c] = dp[cur_a][cur_b][cur_c] + 1;
          previous_a[d][cur_b][cur_c] = cur_a;
          previous_b[d][cur_b][cur_c] = cur_b;
          previous_c[d][cur_b][cur_c] = cur_c;
          as.push(d);
          bs.push(cur_b);
          cs.push(cur_c);
        }
      }
    }
    for (int d = 1; d <= n; d++) {
      if (d != cur_a && d != cur_b && d != cur_c) {
        if (matrix[cur_b][d] == matrix[cur_a][cur_c] &&
            !visited[cur_a][d][cur_c]) {
          visited[cur_a][d][cur_c] = true;
          dp[cur_a][d][cur_c] = dp[cur_a][cur_b][cur_c] + 1;
          previous_a[cur_a][d][cur_c] = cur_a;
          previous_b[cur_a][d][cur_c] = cur_b;
          previous_c[cur_a][d][cur_c] = cur_c;
          as.push(cur_a);
          bs.push(d);
          cs.push(cur_c);
        }
      }
    }
    for (int d = 1; d <= n; d++) {
      if (d != cur_a && d != cur_b && d != cur_c) {
        if (matrix[cur_c][d] == matrix[cur_a][cur_b] &&
            !visited[cur_a][cur_b][d]) {
          visited[cur_a][cur_b][d] = true;
          dp[cur_a][cur_b][d] = dp[cur_a][cur_b][cur_c] + 1;
          previous_a[cur_a][cur_b][d] = cur_a;
          previous_b[cur_a][cur_b][d] = cur_b;
          previous_c[cur_a][cur_b][d] = cur_c;
          as.push(cur_a);
          bs.push(cur_b);
          cs.push(d);
        }
      }
    }
  }
  int cur_min = INT_MAX;
  int min_a = -1, min_b = -1, min_c = -1;
  if (dp[1][2][3] < cur_min && dp[1][2][3] != -1) {
    min_a = 1, min_b = 2, min_c = 3;
    cur_min = dp[1][2][3];
  }
  if (dp[1][3][2] < cur_min && dp[1][3][2] != -1) {
    min_a = 1, min_b = 3, min_c = 2;
    cur_min = dp[1][3][2];
  }
  if (dp[2][1][3] < cur_min && dp[2][1][3] != -1) {
    min_a = 2, min_b = 1, min_c = 3;
    cur_min = dp[2][1][3];
  }
  if (dp[2][3][1] < cur_min && dp[2][3][1] != -1) {
    min_a = 2, min_b = 3, min_c = 1;
    cur_min = dp[2][3][1];
  }
  if (dp[3][1][2] < cur_min && dp[3][1][2] != -1) {
    min_a = 3, min_b = 1, min_c = 2;
    cur_min = dp[3][1][2];
  }
  if (dp[3][2][1] < cur_min && dp[3][2][1] != -1) {
    min_a = 3, min_b = 2, min_c = 1;
    cur_min = dp[3][2][1];
  }
  if (cur_min == INT_MAX) {
    cout << -1;
    return 0;
  }
  cout << dp[min_a][min_b][min_c] << endl;
  vector<int> path_a;
  vector<int> path_b;
  vector<int> path_c;
  int cur_a = min_a, cur_b = min_b, cur_c = min_c;
  while (dp[cur_a][cur_b][cur_c] != -1) {
    path_a.push_back(cur_a);
    path_b.push_back(cur_b);
    path_c.push_back(cur_c);
    int n_cur_a = previous_a[cur_a][cur_b][cur_c];
    int n_cur_b = previous_b[cur_a][cur_b][cur_c];
    int n_cur_c = previous_c[cur_a][cur_b][cur_c];
    cur_a = n_cur_a;
    cur_b = n_cur_b;
    cur_c = n_cur_c;
  }
  path_a.push_back(a);
  path_b.push_back(b);
  path_c.push_back(c);
  reverse(path_a.begin(), path_a.end());
  reverse(path_b.begin(), path_b.end());
  reverse(path_c.begin(), path_c.end());
  for (int i = 0; i < path_a.size() - 1; i++) {
    if (path_a[i] != path_a[i + 1]) {
      printf("%d %d\n", path_a[i], path_a[i + 1]);
    } else if (path_b[i] != path_b[i + 1]) {
      printf("%d %d\n", path_b[i], path_b[i + 1]);
    } else if (path_c[i] != path_c[i + 1]) {
      printf("%d %d\n", path_c[i], path_c[i + 1]);
    }
  }
}