#include <bits/stdc++.h>
using namespace std;
long long a, b, A[4][4], B[4][4];
long long aw[100], bw[100];
long long check[4][4];
long long k;
long long w(long long aa, long long bb) {
  if (aa == bb) return 0;
  if (aa - bb == 1 || aa - bb == -2) return 1;
  return -1;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> a >> b;
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= 3; j++) {
      cin >> A[i][j];
    }
  }
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= 3; j++) {
      cin >> B[i][j];
    }
  }
  check[a][b] = 1;
  long long cura = a, curb = b;
  long long cnt = 1;
  long long chuky;
  if (w(cura, curb) == 1) {
    aw[cnt] = aw[cnt - 1] + 1;
    bw[cnt] = bw[cnt - 1];
  } else if (w(cura, curb) == -1) {
    bw[cnt] = bw[cnt - 1] + 1;
    aw[cnt] = aw[cnt - 1];
  } else {
    aw[cnt] = aw[cnt - 1];
    bw[cnt] = bw[cnt - 1];
  }
  while (1) {
    long long tmpa = A[cura][curb];
    long long tmpb = B[cura][curb];
    cura = tmpa;
    curb = tmpb;
    cnt++;
    if (w(cura, curb) == 1) {
      aw[cnt] = aw[cnt - 1] + 1;
      bw[cnt] = bw[cnt - 1];
    } else if (w(cura, curb) == -1) {
      bw[cnt] = bw[cnt - 1] + 1;
      aw[cnt] = aw[cnt - 1];
    } else {
      aw[cnt] = aw[cnt - 1];
      bw[cnt] = bw[cnt - 1];
    }
    if (check[cura][curb]) {
      chuky = cnt - check[cura][curb];
      break;
    }
    check[cura][curb] = cnt;
  }
  long long t = check[cura][curb];
  if (k < t) {
    cout << aw[k] << ' ' << bw[k] << endl;
    return 0;
  }
  long long achuky = aw[cnt] - aw[t];
  long long bchuky = bw[cnt] - bw[t];
  long long resa = aw[t - 1];
  long long resb = bw[t - 1];
  resa += (k - t + 1) / chuky * achuky;
  resb += (k - t + 1) / chuky * bchuky;
  k = k - t + 1;
  k %= chuky;
  resa += aw[t + k - 1] - aw[t - 1];
  resb += bw[t + k - 1] - bw[t - 1];
  cout << resa << ' ' << resb;
  return 0;
}
