#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
class DP {
 public:
  int cost;
  int stones[3];
  vector<pair<int, int> > logs;
  DP() {}
  DP(int cc) { cost = cc; }
  bool operator<(const DP &opp) const { return cost > opp.cost; }
};
int memo[71][71][71];
char g[80][80];
int main() {
  int n;
  cin >> n;
  DP S;
  S.cost = 0;
  for (int i = 0; i < (int)(3); i++) cin >> S.stones[i];
  for (int i = 0; i < (int)(n); i++) cin >> &g[i + 1][1];
  sort(S.stones, S.stones + 3);
  for (int i = 0; i < (int)(71); i++)
    for (int j = 0; j < (int)(71); j++)
      for (int k = 0; k < (int)(71); k++) memo[i][j][k] = INF;
  priority_queue<DP> dp;
  dp.push(S);
  while (!dp.empty()) {
    S = dp.top();
    dp.pop();
    if (S.stones[2] == 3) break;
    for (int i = 0; i < 3; i++) {
      int s = S.stones[0];
      int t = S.stones[1];
      int v = S.stones[2];
      if (i == 0) swap(v, s);
      if (i == 1) swap(v, t);
      for (int j = 1; j <= n; j++) {
        if (v != j && s != j && t != j && g[s][t] == g[v][j]) {
          DP T = S;
          T.logs.push_back(pair<int, int>(v, j));
          T.cost++;
          T.stones[0] = s;
          T.stones[1] = t;
          T.stones[2] = j;
          sort(T.stones, T.stones + 3);
          if (memo[T.stones[0]][T.stones[1]][T.stones[2]] > T.cost) {
            memo[T.stones[0]][T.stones[1]][T.stones[2]] = T.cost;
            dp.push(T);
          }
        }
      }
    }
  }
  if (S.stones[2] == 3) {
    cout << S.logs.size() << endl;
    for (__typeof((S.logs).begin()) it = (S.logs).begin(); it != (S.logs).end();
         ++it)
      cout << it->first << " " << it->second << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
