#include <bits/stdc++.h>
using namespace std;
const int N = 80;
int n, x, dp[N][N][N];
string adj[N];
vector<int> par[N][N][N];
queue<vector<int> > q;
void bfs() {
  while (!q.empty()) {
    vector<int> v = q.front();
    q.pop();
    for (int i = 0; i < n; i++)
      if (i != v[0] && i != v[1] && i != v[2]) {
        if (adj[v[0]][i] == adj[v[1]][v[2]] && !dp[i][v[1]][v[2]]) {
          dp[i][v[1]][v[2]] = dp[v[0]][v[1]][v[2]] + 1;
          par[i][v[1]][v[2]] = v;
          vector<int> u = v;
          u[0] = i;
          q.push(u);
        }
        if (adj[v[1]][i] == adj[v[0]][v[2]] && !dp[v[0]][i][v[2]]) {
          dp[v[0]][i][v[2]] = dp[v[0]][v[1]][v[2]] + 1;
          par[v[0]][i][v[2]] = v;
          vector<int> u = v;
          u[1] = i;
          q.push(u);
        }
        if (adj[v[2]][i] == adj[v[0]][v[1]] && !dp[v[0]][v[1]][i]) {
          dp[v[0]][v[1]][i] = dp[v[0]][v[1]][v[2]] + 1;
          par[v[0]][v[1]][i] = v;
          vector<int> u = v;
          u[2] = i;
          q.push(u);
        }
      }
  }
}
void output(vector<int> v) {
  if (dp[v[0]][v[1]][v[2]] <= 1) {
    return;
  }
  vector<int> a = par[v[0]][v[1]][v[2]];
  output(a);
  for (int i = 0; i < 3; i++)
    if (a[i] != v[i]) {
      cout << a[i] + 1 << ' ' << v[i] + 1 << '\n';
      return;
    }
}
int main() {
  cin.sync_with_stdio(false);
  vector<int> a(3);
  cin >> n >> a[0] >> a[1] >> a[2];
  a[0]--, a[1]--, a[2]--;
  for (int i = 0; i < n; i++) cin >> adj[i];
  sort(a.begin(), a.end());
  do {
    dp[a[0]][a[1]][a[2]] = 1;
    q.push(a);
  } while (next_permutation(a.begin(), a.end()));
  bfs();
  for (int i = 0; i < 3; i++) a[i] = i;
  cout << dp[0][1][2] - 1 << '\n';
  output(a);
  return 0;
}
