#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const auto INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
int A[4][4], B[4][4];
int visit[4][4];
pair<int, int> pre[N];
int Ans[4][4];
int main() {
  Ans[3][2] = 1;
  Ans[2][1] = 1;
  Ans[1][3] = 1;
  long long k;
  int a, b;
  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]);
  }
  long long ans1 = Ans[a][b];
  long long ans2 = Ans[b][a];
  if (k == 1) {
    printf("%lld %lld\n", ans1, ans2);
    return 0;
  }
  int ans = -1, TT = 0;
  k--;
  for (long long T = 1; T <= min((long long)100000, k); T++) {
    int AA = A[a][b];
    int BB = B[a][b];
    a = AA;
    b = BB;
    if (visit[a][b]) {
      TT = visit[a][b] - 1;
      ans = (int)T - visit[a][b];
      break;
    }
    visit[a][b] = (int)T;
    pre[T].first = Ans[a][b] + pre[T - 1].first;
    pre[T].second = Ans[b][a] + pre[T - 1].second;
  }
  if (ans == -1) {
    printf("%lld %lld\n", ans1 + pre[k].first, ans2 + pre[k].second);
  } else {
    k--;
    k -= TT;
    ans1 += pre[TT].first;
    ans2 += pre[TT].second;
    ans1 +=
        ((long long)k / ans) * (long long)(pre[ans + TT].first - pre[TT].first);
    ans2 += ((long long)k / ans) *
            (long long)(pre[ans + TT].second - pre[TT].second);
    k = k % ans;
    ans1 += (long long)(pre[k + TT + 1].first - pre[TT].first);
    ans2 += (long long)(pre[k + TT + 1].second - pre[TT].second);
    printf("%lld %lld\n", ans1, ans2);
  }
}
