#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>
inline void gadd(T1 &a, T2 b) {
  a = (a + b) % Z;
}
int casenum, casei;
long long K;
int a, b;
long long A[5][5][65], B[5][5][65], win[5][5][65], lose[5][5][65];
int main() {
  while (~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][0]);
      }
    }
    for (int i = 1; i <= 3; ++i) {
      for (int j = 1; j <= 3; ++j) {
        scanf("%d", &B[i][j][0]);
      }
    }
    for (int i = 1; i <= 3; ++i) {
      for (int j = 1; j <= 3; ++j) {
        win[i][j][0] = (i - j == 1 || i - j == -2);
        lose[i][j][0] = (i - j == -1 || i - j == 2);
      }
    }
    for (int k = 1; k <= 60; ++k) {
      for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
          int ii = A[i][j][k - 1];
          int jj = B[i][j][k - 1];
          A[i][j][k] = A[ii][jj][k - 1];
          B[i][j][k] = B[ii][jj][k - 1];
          win[i][j][k] = win[i][j][k - 1] + win[ii][jj][k - 1];
          lose[i][j][k] = lose[i][j][k - 1] + lose[ii][jj][k - 1];
        }
      }
    }
    long long ans1 = 0, ans2 = 0;
    for (int k = 0; k <= 60; ++k)
      if (K >> k & 1) {
        ans1 += win[a][b][k];
        ans2 += lose[a][b][k];
        int aa = A[a][b][k];
        int bb = B[a][b][k];
        a = aa;
        b = bb;
      }
    printf("%lld %lld\n", ans1, ans2);
  }
  return 0;
}
