#include <bits/stdc++.h>
using namespace std;
const int maxn = 70;
const int inf = 0x7f7f7f7f;
class State {
 public:
  int a;
  int b;
  int c;
  State(void);
  State(int, int, int);
};
State::State(void) : a(0), b(0), c(0) {}
State::State(int a, int b, int c) : a(a), b(b), c(c) {}
int n;
int inita, initb, initc;
char clr[maxn][maxn + 1];
int d[maxn][maxn][maxn];
State p[maxn][maxn][maxn];
int E[maxn][26][maxn];
int Esz[maxn][26];
State que[maxn * maxn * maxn];
int qh, qt;
pair<int, int> stk[maxn * maxn * maxn];
int sh;
bool flg[2][3];
inline void validate(int& a, int& b, int& c) {
  if (a > b) swap(a, b);
  if (a > c) swap(a, c);
  if (b > c) swap(b, c);
}
int main(void) {
  int i, j, k;
  State cur, tgt, tmp;
  int curd, c, a, b;
  scanf("%d", &n);
  scanf("%d %d %d", &inita, &initb, &initc);
  for (i = 0; i < n; ++i) scanf("%s", clr[i]);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      if (i == j) continue;
      c = clr[i][j] - 'a';
      E[i][c][Esz[i][c]] = j;
      ++Esz[i][c];
    }
  }
  --inita;
  --initb;
  --initc;
  memset(d, inf, sizeof(d));
  validate(inita, initb, initc);
  d[inita][initb][initc] = 0;
  qh = 0;
  qt = 1;
  que[qh] = State(inita, initb, initc);
  for (; qh < qt && d[0][1][2] == inf; ++qh) {
    cur = que[qh];
    curd = d[cur.a][cur.b][cur.c];
    for (k = 0; k < 3; ++k) {
      if (k == 1)
        swap(cur.a, cur.b);
      else if (k == 2)
        swap(cur.a, cur.c);
      c = clr[cur.b][cur.c] - 'a';
      for (i = 0; i < Esz[cur.a][c]; ++i) {
        tgt = cur;
        tgt.a = E[cur.a][c][i];
        if (tgt.a == cur.b || tgt.a == cur.c) continue;
        validate(tgt.a, tgt.b, tgt.c);
        if (d[tgt.a][tgt.b][tgt.c] == inf) {
          d[tgt.a][tgt.b][tgt.c] = curd + 1;
          que[qt] = tgt;
          ++qt;
          tmp = cur;
          validate(tmp.a, tmp.b, tmp.c);
          p[tgt.a][tgt.b][tgt.c] = tmp;
          if (d[0][1][2] < inf) break;
        }
      }
      if (d[0][1][2] < inf) break;
    }
  }
  if (d[0][1][2] == inf)
    printf("-1\n");
  else {
    printf("%d\n", d[0][1][2]);
    curd = d[0][1][2];
    for (cur = State(0, 1, 2); curd > 0; --curd) {
      memset(flg, false, sizeof(flg));
      for (i = 0; i < 3; ++i) {
        if (i == 0)
          a = cur.a;
        else if (i == 1)
          a = cur.b;
        else
          a = cur.c;
        for (j = 0; j < 3; ++j) {
          if (j == 0)
            b = p[cur.a][cur.b][cur.c].a;
          else if (j == 1)
            b = p[cur.a][cur.b][cur.c].b;
          else
            b = p[cur.a][cur.b][cur.c].c;
          if (a == b) {
            flg[0][i] = true;
            flg[1][j] = true;
            break;
          }
        }
      }
      for (i = 0; i < 3; ++i) {
        if (!flg[0][i]) break;
      }
      if (i == 0)
        a = cur.a;
      else if (i == 1)
        a = cur.b;
      else
        a = cur.c;
      for (j = 0; j < 3; ++j) {
        if (!flg[1][j]) break;
      }
      if (j == 0)
        b = p[cur.a][cur.b][cur.c].a;
      else if (j == 1)
        b = p[cur.a][cur.b][cur.c].b;
      else
        b = p[cur.a][cur.b][cur.c].c;
      stk[sh] = pair<int, int>(b, a);
      ++sh;
      cur = p[cur.a][cur.b][cur.c];
    }
    for (; sh > 0; --sh)
      printf("%d %d\n", stk[sh - 1].first + 1, stk[sh - 1].second + 1);
  }
  return 0;
}
