#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
  ios::sync_with_stdio(false);
  run();
}
char colour[70][70];
char act[70][70][70][2];
char bfs[54740 + 1234][3];
int bfn = 1;
void fix(int &a, int &b, int &c) {
  if (a > b) swap(a, b);
  if (a > c) swap(a, c);
  if (b > c) swap(b, c);
}
void push(int a, int b, int s, int t) {
  int c = t;
  if (colour[s][t] != colour[a][b]) return;
  if (a == t or b == t or s == t) return;
  fix(a, b, c);
  if (act[a][b][c][0] == -1) {
    act[a][b][c][0] = s;
    act[a][b][c][1] = t;
    bfs[bfn][0] = a;
    bfs[bfn][1] = b;
    bfs[bfn][2] = c;
    ++bfn;
  }
}
void run() {
  int n;
  cin >> n;
  int sx, sy, sz;
  cin >> sx >> sy >> sz;
  --sx, --sy, --sz;
  fix(sx, sy, sz);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) {
      colour[i][j] = (i == j ? -1 : s[j] - 'a');
    }
  }
  memset(act, -1, sizeof act);
  act[sx][sy][sz][0] = 0;
  bfs[0][0] = sx, bfs[0][1] = sy, bfs[0][2] = sz;
  for (int id = 0; id < bfn; id++) {
    int x = bfs[id][0], y = bfs[id][1], z = bfs[id][2];
    for (int i = 0; i < n; i++) {
      push(y, z, x, i);
      push(x, z, y, i);
      push(x, y, z, i);
    }
  }
  if (act[0][1][2][0] == -1) {
    cout << "-1" << endl;
    return;
  }
  vector<pair<unsigned short, unsigned short>> moves;
  for (int x = 0, y = 1, z = 2; x != sx or y != sy or z != sz; fix(x, y, z)) {
    int a = act[x][y][z][0];
    int b = act[x][y][z][1];
    moves.push_back({a + 1, b + 1});
    if (x == b)
      x = a;
    else if (y == b)
      y = a;
    else if (z == b)
      z = a;
    else
      assert(false);
  }
  cout << moves.size() << endl;
  reverse(moves.begin(), moves.end());
  for (auto i : moves) cout << i.first << " " << i.second << endl;
}
