#include <bits/stdc++.h>
using namespace std;
const int N = 71, A = 26, INF = 1 << 30;
int n, a[3], col[N][N], vis[N][N][N], dis[N][N][N], cnt = INF;
vector<int> adj[A][N];
vector<pair<int, int>> ans;
char c;
struct node {
  int x, y, z;
} par[N][N][N], start;
queue<node> q;
pair<int, int> operator-(node a, node b) {
  return {(a.x != b.x) * a.x + (a.y != b.y) * a.y + (a.z != b.z) * a.z,
          (a.x != b.x) * b.x + (a.y != b.y) * b.y + (a.z != b.z) * b.z};
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> a[0] >> a[1] >> a[2];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> c;
      adj[col[i][j] = c - 'a'][i].push_back(j);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) fill(dis[i][j], dis[i][j] + n, INF);
  dis[0][1][2] = 0;
  vis[0][1][2] = 1;
  q.push(start = {0, 1, 2});
  while (q.size()) {
    node u = q.front();
    q.pop();
    int d = dis[u.x][u.y][u.z];
    for (int v : adj[col[u.x][u.y]][u.z])
      if (!vis[u.x][u.y][v] && v ^ u.x && v ^ u.y) {
        dis[u.x][u.y][v] = d + 1;
        vis[u.x][u.y][v] = 1;
        par[u.x][u.y][v] = u;
        q.push({u.x, u.y, v});
      }
    for (int v : adj[col[u.x][u.z]][u.y])
      if (!vis[u.x][v][u.z] && v ^ u.x && v ^ u.z) {
        dis[u.x][v][u.z] = d + 1;
        vis[u.x][v][u.z] = 1;
        par[u.x][v][u.z] = u;
        q.push({u.x, v, u.z});
      }
    for (int v : adj[col[u.y][u.z]][u.x])
      if (!vis[v][u.y][u.z] && v ^ u.y && v ^ u.z) {
        dis[v][u.y][u.z] = d + 1;
        vis[v][u.y][u.z] = 1;
        par[v][u.y][u.z] = u;
        q.push({v, u.y, u.z});
      }
  }
  a[0]--, a[1]--, a[2]--;
  sort(a, a + 3);
  do {
    if (cnt > dis[a[0]][a[1]][a[2]]) {
      cnt = dis[a[0]][a[1]][a[2]];
      node u = {a[0], a[1], a[2]};
      ans.clear();
      while (u.x ^ 0 || u.y ^ 1 || u.z ^ 2) {
        ans.push_back(u - par[u.x][u.y][u.z]);
        u = par[u.x][u.y][u.z];
      }
    }
  } while (next_permutation(a, a + 3));
  if (cnt == INF) return cout << -1 << endl, 0;
  cout << cnt << endl;
  for (auto x : ans) cout << x.first + 1 << ' ' << x.second + 1 << endl;
}
