#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
pair<int, int> back[75][75][75];
int n;
char g[75][75];
void solve(int vs[3]) {
  vector<pair<int, int> > way;
  while (back[vs[0]][vs[1]][vs[2]].first != -2) {
    pair<int, int> d = back[vs[0]][vs[1]][vs[2]];
    way.push_back(make_pair(d.second, vs[d.first]));
    vs[d.first] = d.second;
  }
  reverse((way).begin(), (way).end());
  cout << way.size() << endl;
  for (int i = 0; i < (way.size()); ++i)
    printf("%d %d\n", way[i].first + 1, way[i].second + 1);
}
int main() {
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;
  --a;
  --b;
  --c;
  for (int i = 0; i < (n); ++i) scanf("%s", g[i]);
  memset(back, -1, sizeof(back));
  back[a][b][c] = make_pair(-2, -2);
  queue<pair<int, pair<int, int> > > Q;
  Q.push(make_pair(a, make_pair(b, c)));
  while (!Q.empty()) {
    pair<int, pair<int, int> > cur = Q.front();
    Q.pop();
    int vs[3] = {cur.first, cur.second.first, cur.second.second};
    int tmp[3] = {vs[0], vs[1], vs[2]};
    sort(tmp, tmp + 3);
    if (tmp[2] == 2) {
      solve(vs);
      return 0;
    }
    debug(vs, vs + 3);
    for (int i = 0; i < (3); ++i) {
      char c;
      int p, q;
      for (int j = 0; j < (3); ++j)
        for (int k = 0; k < (3); ++k)
          if (j != i && k != i && j != k) {
            p = vs[j];
            q = vs[k];
            c = g[p][q];
            ;
            ;
          };
      ;
      ;
      ;
      ;
      ;
      ;
      ;
      for (int j = 0; j < (n); ++j)
        if (j != p && j != q && g[vs[i]][j] == c) {
          int tmp = vs[i];
          vs[i] = j;
          if (back[vs[0]][vs[1]][vs[2]].first == -1) {
            ;
            ;
            back[vs[0]][vs[1]][vs[2]] = make_pair(i, tmp);
            Q.push(make_pair(vs[0], make_pair(vs[1], vs[2])));
          }
          vs[i] = tmp;
        }
    }
  }
  printf("-1\n");
  return 0;
}
