#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, c;
};
const int MAXX = 80;
int n, A, B, C, dis[MAXX][MAXX][MAXX];
node par[MAXX][MAXX][MAXX];
bool vis[MAXX][MAXX][MAXX], mark1[MAXX], mark2[MAXX];
string s[MAXX];
void Sort(int &x, int &y, int &z) {
  if (x > y) swap(x, y);
  if (y > z) swap(y, z);
  if (x > y) swap(x, y);
}
void bfs() {
  queue<node> q;
  par[0][1][2] = {-1, -1, -1};
  dis[0][1][2] = 0;
  vis[0][1][2] = 1;
  q.push({0, 1, 2});
  while (q.size()) {
    node x = q.front();
    int tmpa = x.a, tmpb = x.b, tmpc = x.c, tmpi;
    q.pop();
    for (int i = 0; i < n; i++) {
      tmpa = x.a, tmpb = x.b, tmpc = x.c, tmpi = i;
      Sort(tmpi, tmpb, tmpc);
      if (i != x.a && i != x.b && i != x.c && s[x.a][i] == s[x.b][x.c] &&
          !vis[tmpi][tmpb][tmpc]) {
        q.push({tmpi, tmpb, tmpc}),
            vis[tmpi][tmpb][tmpc] = 1,
            dis[tmpi][tmpb][tmpc] = dis[x.a][x.b][x.c] + 1;
        par[tmpi][tmpb][tmpc] = x;
      }
    }
    for (int i = 0; i < n; i++) {
      tmpa = x.a, tmpb = x.b, tmpc = x.c, tmpi = i;
      Sort(tmpa, tmpi, tmpc);
      if (i != x.a && i != x.b && i != x.c && s[x.b][i] == s[x.a][x.c] &&
          !vis[tmpa][tmpi][tmpc]) {
        q.push({tmpa, tmpi, tmpc}),
            vis[tmpa][tmpi][tmpc] = 1,
            dis[tmpa][tmpi][tmpc] = dis[x.a][x.b][x.c] + 1;
        par[tmpa][tmpi][tmpc] = x;
      }
    }
    for (int i = 0; i < n; i++) {
      tmpa = x.a, tmpb = x.b, tmpc = x.c, tmpi = i;
      Sort(tmpa, tmpb, tmpi);
      if (i != x.a && i != x.b && i != x.c && s[x.c][i] == s[x.a][x.b] &&
          !vis[tmpa][tmpb][tmpi]) {
        q.push({tmpa, tmpb, tmpi}),
            vis[tmpa][tmpb][tmpi] = 1,
            dis[tmpa][tmpb][tmpi] = dis[x.a][x.b][x.c] + 1;
        par[tmpa][tmpb][tmpi] = x;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> A >> B >> C;
  A--, B--, C--;
  Sort(A, B, C);
  for (int i = 0; i < n; i++) cin >> s[i];
  bfs();
  if (!vis[A][B][C]) return cout << -1 << endl, 0;
  cout << dis[A][B][C] << endl;
  node x = {A, B, C};
  while ((par[x.a][x.b][x.c].a) != -1) {
    node tmp = par[x.a][x.b][x.c];
    int arr1[3] = {x.a, x.b, x.c};
    int arr2[3] = {tmp.a, tmp.b, tmp.c};
    for (int i = 0; i < 3; i++) mark1[arr1[i]] = 1, mark2[arr2[i]] = 1;
    for (int i = 0; i < 3; i++)
      if (!mark2[arr1[i]]) cout << arr1[i] + 1 << " ";
    for (int i = 0; i < 3; i++)
      if (!mark1[arr2[i]]) cout << arr2[i] + 1 << endl;
    for (int i = 0; i < 3; i++) mark1[arr1[i]] = mark2[arr2[i]] = 0;
    x = tmp;
  }
}
