#include <bits/stdc++.h>
bool is_checked[70][70][70];
int states[60000];
int parent[60000];
int next[60000];
int front = 0;
int back = 0;
char map[71][71];
int n;
inline bool checked(int stones[3]);
inline bool checked(int state);
inline void state2stones(int state, int stones[3]);
inline int stones2state(int stones[3]);
inline void set_checked(int stones[3]);
bool find_it(int stones[3]);
int main() {
  scanf("%d", &n);
  int stones[3];
  for (int i = 0; i < 3; i++) {
    scanf("%d", &stones[i]);
    stones[i]--;
  }
  for (int i = 0; i < n; i++) {
    gets(map[i]);
    if (strlen(map[i]) == 0) {
      i--;
    }
  }
  bool found = find_it(stones);
  if (!found) {
    printf("-1");
  } else {
    int steps = 0;
    int s = back - 1;
    while (parent[s] != -1) {
      next[parent[s]] = s;
      s = parent[s];
      steps++;
    }
    printf("%d\n", steps);
    s = next[0];
    int stones_last[3];
    state2stones(states[0], stones_last);
    for (int i = 0; i < steps; i++) {
      state2stones(states[s], stones);
      for (int j = 0; j < 3; j++) {
        if (stones[j] != stones_last[j]) {
          printf("%d %d\n", stones_last[j] + 1, stones[j] + 1);
          stones_last[j] = stones[j];
          break;
        }
      }
      s = next[s];
    }
  }
  return 0;
}
bool find_it(int stones[3]) {
  states[back] = stones2state(stones);
  parent[back++] = -1;
  if (stones[0] >= 0 && stones[0] <= 2 && stones[1] >= 0 && stones[1] <= 2 &&
      stones[2] >= 0 && stones[2] <= 2) {
    return true;
  }
  while (front < back) {
    int state = states[front];
    state2stones(state, stones);
    int stones_temp[3];
    stones_temp[1] = stones[1];
    stones_temp[2] = stones[2];
    for (int i = 0; i < n; i++) {
      if (i == stones[0] || i == stones[1] || i == stones[2]) {
        continue;
      }
      if (map[i][stones[0]] == map[stones[1]][stones[2]]) {
        stones_temp[0] = i;
        if (!checked(stones_temp)) {
          states[back] = stones2state(stones_temp);
          parent[back++] = front;
          set_checked(stones_temp);
          if (stones_temp[0] >= 0 && stones_temp[0] <= 2 &&
              stones_temp[1] >= 0 && stones_temp[1] <= 2 &&
              stones_temp[2] >= 0 && stones_temp[2] <= 2) {
            return true;
          }
        }
      }
    }
    stones_temp[0] = stones[0];
    stones_temp[2] = stones[2];
    for (int i = 0; i < n; i++) {
      if (i == stones[0] || i == stones[1] || i == stones[2]) {
        continue;
      }
      if (map[i][stones[1]] == map[stones[0]][stones[2]]) {
        stones_temp[1] = i;
        if (!checked(stones_temp)) {
          states[back] = stones2state(stones_temp);
          parent[back++] = front;
          set_checked(stones_temp);
          if (stones_temp[0] >= 0 && stones_temp[0] <= 2 &&
              stones_temp[1] >= 0 && stones_temp[1] <= 2 &&
              stones_temp[2] >= 0 && stones_temp[2] <= 2) {
            return true;
          }
        }
      }
    }
    stones_temp[0] = stones[0];
    stones_temp[1] = stones[1];
    for (int i = 0; i < n; i++) {
      if (i == stones[0] || i == stones[1] || i == stones[2]) {
        continue;
      }
      if (map[i][stones[2]] == map[stones[0]][stones[1]]) {
        stones_temp[2] = i;
        if (!checked(stones_temp)) {
          states[back] = stones2state(stones_temp);
          parent[back++] = front;
          set_checked(stones_temp);
          if (stones_temp[0] >= 0 && stones_temp[0] <= 2 &&
              stones_temp[1] >= 0 && stones_temp[1] <= 2 &&
              stones_temp[2] >= 0 && stones_temp[2] <= 2) {
            return true;
          }
        }
      }
    }
    front++;
  }
  return false;
}
inline bool checked(int stones[3]) {
  return (
      (stones[0] < stones[1])
          ? (stones[1] < stones[2])
                ? is_checked[stones[0]][stones[1]][stones[2]]
            : (stones[2] < stones[0])
                ? is_checked[stones[2]][stones[0]][stones[1]]
                : is_checked[stones[0]][stones[2]][stones[1]]
      : (stones[2] < stones[1]) ? is_checked[stones[2]][stones[1]][stones[0]]
      : (stones[0] < stones[2]) ? is_checked[stones[1]][stones[0]][stones[2]]
                                : is_checked[stones[1]][stones[2]][stones[0]]);
}
inline bool checked(int state) {
  int stones[3];
  state2stones(state, stones);
  return checked(stones);
}
inline void set_checked(int stones[3]) {
  ((stones[0] < stones[1])
       ? (stones[1] < stones[2])   ? is_checked[stones[0]][stones[1]][stones[2]]
         : (stones[2] < stones[0]) ? is_checked[stones[2]][stones[0]][stones[1]]
                                   : is_checked[stones[0]][stones[2]][stones[1]]
   : (stones[2] < stones[1]) ? is_checked[stones[2]][stones[1]][stones[0]]
   : (stones[0] < stones[2]) ? is_checked[stones[1]][stones[0]][stones[2]]
                             : is_checked[stones[1]][stones[2]][stones[0]]) =
      true;
}
inline void state2stones(int state, int stones[3]) {
  stones[0] = state & 0x000000FF;
  stones[1] = (state >> 8) & 0x000000FF;
  stones[2] = (state >> 16) & 0x000000FF;
}
inline int stones2state(int stones[3]) {
  return ((stones[2] & 0x000000FF) << 16) | ((stones[1] & 0x000000FF) << 8) |
         (stones[0] & 0x000000FF);
}
