#include <bits/stdc++.h>
using namespace std;
struct state {
  int arr[3];
  int prev, cur;
};
char g[77][77];
bool vis[72][72][72];
int tar[3] = {0, 1, 2};
int prevIdx[360000];
vector<state> q;
vector<pair<int, int> > path;
int main() {
  int n;
  scanf("%d", &n);
  state st;
  scanf("%d%d%d", &(st.arr[0]), &(st.arr[1]), &(st.arr[2]));
  for (int i = 0; i < 3; i++) st.arr[i]--;
  st.prev = -1, st.cur = -1;
  for (int i = 0; i < n; i++) {
    scanf("%s", g[i]);
  }
  q.push_back(st);
  vis[st.arr[0]][st.arr[1]][st.arr[2]] = 1;
  memset((prevIdx), (-1), sizeof(prevIdx));
  int steps = 0, idx = 0;
  bool yes = 0;
  while (idx < q.size()) {
    int siz = q.size();
    for (; idx < siz; idx++) {
      st = q[idx];
      if (!memcmp(st.arr, tar, sizeof(tar))) {
        yes = 1;
        goto end;
      }
      state stnxt;
      for (int i = 0; i < 3; i++) {
        int n1 = st.arr[i];
        int n2 = st.arr[(i + 1) % 3];
        int n3 = st.arr[(i + 2) % 3];
        for (int x = 0; x < n; x++) {
          if (find(st.arr, st.arr + 3, x) < (st.arr + 3)) continue;
          if (g[n1][x] != g[n2][n3]) continue;
          int nxt[] = {x, n2, n3};
          sort(nxt, nxt + 3);
          if (vis[nxt[0]][nxt[1]][nxt[2]]) continue;
          vis[nxt[0]][nxt[1]][nxt[2]] = 1;
          memcpy(stnxt.arr, nxt, sizeof(nxt));
          stnxt.prev = n1, stnxt.cur = x;
          q.push_back(stnxt);
          prevIdx[q.size() - 1] = idx;
        }
      }
    }
    steps++;
  }
end:
  if (!yes) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", steps);
  while (idx >= 0) {
    st = q[idx];
    if (st.prev == -1) break;
    path.push_back(make_pair((st.prev), (st.cur)));
    idx = prevIdx[idx];
  }
  for (int i = ((int)(path).size()) - 1; i >= 0; i -= 1)
    printf("%d %d\n", path[i].first + 1, path[i].second + 1);
  return 0;
}
