#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int N = 4;
int A, B;
long long k;
int a[N][N], b[N][N];
int cnt[N][N];
int point_A[10000007];
int point_B[10000007];
bool ok(int a, int b) {
  if (a == 3 && b == 2) return 1;
  if (a == 2 && b == 1) return 1;
  if (a == 1 && b == 3) return 1;
  return 0;
}
int main() {
  scanf("%lld %d %d", &k, &A, &B);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &(a[i][j]));
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &(b[i][j]));
  cnt[A][B] = 1;
  if (A != B) {
    if (ok(A, B))
      point_A[1] = 1;
    else
      point_B[1] = 1;
  }
  int nxt_A = a[A][B], nxt_B = b[A][B];
  int K = 1;
  long long alice = 0, bob = 0;
  long long cyc = 0, A_ = 0, B_ = 0;
  int beg = 0;
  while (1) {
    if (cnt[nxt_A][nxt_B]) {
      int last = cnt[nxt_A][nxt_B];
      cyc = K - last + 1;
      beg = last;
      A_ = 0LL + point_A[K] - point_A[last - 1];
      B_ = 0LL + point_B[K] - point_B[last - 1];
      last--;
      if (last > k) last = k;
      alice = alice + point_A[last];
      bob = bob + point_B[last];
      k -= beg - 1;
      break;
    }
    cnt[nxt_A][nxt_B] = ++K;
    if (nxt_A == nxt_B) {
      point_A[K] = point_A[K - 1];
      point_B[K] = point_B[K - 1];
    } else {
      if (ok(nxt_A, nxt_B)) {
        point_A[K] = point_A[K - 1] + 1;
        point_B[K] = point_B[K - 1];
      } else {
        point_A[K] = point_A[K - 1];
        point_B[K] = point_B[K - 1] + 1;
      }
    }
    int tony = nxt_A, mars = nxt_B;
    nxt_A = a[tony][mars];
    nxt_B = b[tony][mars];
  }
  if (k > 0) {
    long long times = (1LL * k) / cyc;
    k -= (times * cyc);
    alice += times * A_;
    bob += times * B_;
    if (k > 0) {
      alice += 0LL + point_A[beg + k - 1] - point_A[beg - 1];
      bob += 0LL + point_B[beg + k - 1] - point_B[beg - 1];
    }
  }
  printf("%lld %lld", alice, bob);
  return 0;
}
