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 long long MXN = 70 + 10;
const long long MXM = 5e2 + 10;
const long long MX5 = 3e5 + 10;
const long long MX6 = 1e6 + 10;
const long long INF = 8e18;
const long double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
  return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
long long n, a, b, c;
string s[MXN];
queue<pair<pair<long long, long long>, long long> > q;
bool vis[MXN][MXN][MXN];
long long dis[MXN][MXN][MXN];
pair<pair<long long, long long>, long long> par[MXN][MXN][MXN], P;
vector<pair<long long, long long> > vec;
int main() {
  cin >> n >> a >> b >> c;
  a--;
  b--;
  c--;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < MXN; i++) {
    for (int j = 0; j < MXN; j++) {
      for (int h = 0; h < MXN; h++) {
        dis[i][j][h] = INF;
        par[i][j][h] = {{-1, -1}, -1};
      }
    }
  }
  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});
  vis[a][b][c] = 1;
  vis[a][c][b] = 1;
  vis[b][a][c] = 1;
  vis[b][c][a] = 1;
  vis[c][a][b] = 1;
  vis[c][b][a] = 1;
  dis[a][b][c] = 0;
  dis[a][c][b] = 0;
  dis[b][a][c] = 0;
  dis[b][c][a] = 0;
  dis[c][a][b] = 0;
  dis[c][b][a] = 0;
  while (!q.empty()) {
    for (int i = 0; i < n; i++) {
      if (i == q.front().first.first || i == q.front().first.second ||
          i == q.front().second)
        continue;
      if (s[i][q.front().first.first] ==
              s[q.front().first.second][q.front().second] &&
          !vis[i][q.front().first.second][q.front().second]) {
        vis[i][q.front().first.second][q.front().second] = 1;
        dis[i][q.front().first.second][q.front().second] =
            dis[q.front().first.first][q.front().first.second]
               [q.front().second] +
            1;
        par[i][q.front().first.second][q.front().second] = {
            {q.front().first.first, q.front().first.second}, q.front().second};
        q.push({{i, q.front().first.second}, q.front().second});
      }
      if (s[i][q.front().first.second] ==
              s[q.front().first.first][q.front().second] &&
          !vis[q.front().first.first][i][q.front().second]) {
        vis[q.front().first.first][i][q.front().second] = 1;
        dis[q.front().first.first][i][q.front().second] =
            dis[q.front().first.first][q.front().first.second]
               [q.front().second] +
            1;
        par[q.front().first.first][i][q.front().second] = {
            {q.front().first.first, q.front().first.second}, q.front().second};
        q.push({{q.front().first.first, i}, q.front().second});
      }
      if (s[i][q.front().second] ==
              s[q.front().first.second][q.front().first.first] &&
          !vis[q.front().first.first][q.front().first.second][i]) {
        vis[q.front().first.first][q.front().first.second][i] = 1;
        dis[q.front().first.first][q.front().first.second][i] =
            dis[q.front().first.first][q.front().first.second]
               [q.front().second] +
            1;
        par[q.front().first.first][q.front().first.second][i] = {
            {q.front().first.first, q.front().first.second}, q.front().second};
        q.push({{q.front().first.first, q.front().first.second}, i});
      }
    }
    q.pop();
  }
  if (dis[0][1][2] == INF) return cout << -1 << '\n', 0;
  ;
  cout << dis[0][1][2] << '\n';
  long long x = 0, y = 1, z = 2;
  while (par[x][y][z].second != -1) {
    P = par[x][y][z];
    long long x1 = P.first.first, y1 = P.first.second, z1 = P.second;
    if (x1 != x) {
      vec.push_back({x1, x});
    } else if (y1 != y) {
      vec.push_back({y1, y});
    } else {
      vec.push_back({z1, z});
    }
    x = x1, y = y1, z = z1;
  }
  reverse((vec).begin(), (vec).end());
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i].first + 1 << ' ' << vec[i].second + 1 << '\n';
  }
  return 0;
}