#include <bits/stdc++.h>
using namespace std;
int main() {
  int SA, SB;
  long long K;
  scanf("%lld%d%d", &K, &SA, &SB);
  int A[4][4], B[4][4], P[4][4];
  for (int i = (int)(1); i <= (int)(3); ++i)
    for (int j = (int)(1); j <= (int)(3); ++j) scanf("%d", &A[i][j]);
  for (int i = (int)(1); i <= (int)(3); ++i)
    for (int j = (int)(1); j <= (int)(3); ++j) scanf("%d", &B[i][j]);
  using state = tuple<int, int, long long, long long, long long>;
  state T[62][4][4];
  for (int i = (int)(1); i <= (int)(3); ++i)
    for (int j = (int)(1); j <= (int)(3); ++j) {
      int a = i - 1, b = j - 1;
      P[i][j] = (a + 2) % 3 == b ? 1 : 0;
    }
  for (int a = (int)(1); a <= (int)(3); ++a)
    for (int b = (int)(1); b <= (int)(3); ++b) {
      T[0][a][b] = state(A[a][b], B[a][b], P[a][b], a == b, P[b][a]);
    }
  for (int i = (int)(1); i <= (int)(61); ++i)
    for (int a = (int)(1); a <= (int)(3); ++a)
      for (int b = (int)(1); b <= (int)(3); ++b) {
        int aa, bb;
        long long s1, s2, s3, t1, t2, t3;
        tie(aa, bb, s1, s2, s3) = T[i - 1][a][b];
        tie(aa, bb, t1, t2, t3) = T[i - 1][aa][bb];
        T[i][a][b] = state(aa, bb, s1 + t1, s2 + t2, s3 + t3);
      }
  long long sa = 0, sc = 0, sb = 0;
  for (int i = (int)(61); i >= (int)(0); --i)
    if (K >> i & 1) {
      long long s1, s2, s3;
      tie(SA, SB, s1, s2, s3) = T[i][SA][SB];
      sa += s1, sc += s2, sb += s3;
    }
  printf("%lld %lld\n", sa, sb);
  return 0;
}
