#include <bits/stdc++.h>
using namespace std;
int choiceA[4][4], choiceB[4][4];
long long k;
map<pair<long long, long long>, tuple<int, int, int>> estado;
int A, B;
int TIMES;
int statea, stateb;
void get(int a, int b, long long &pa, long long &pb, long long &times) {
  if (times > k) {
    times--;
    return;
  }
  if (estado.find({a, b}) != estado.end()) {
    int a2, b2, t2;
    statea = a, stateb = b;
    tie(a2, b2, t2) = estado[{a, b}];
    A = pa - a2;
    B = pb - b2;
    TIMES = times - t2;
    times--;
    return;
  }
  estado[{a, b}] = make_tuple(pa, pb, times);
  if (a == b) {
    times++;
    get(choiceA[a][b], choiceB[a][b], pa, pb, times);
    return;
  }
  if ((a == 3 && b == 2) || (a == 2 && b == 1) || (a == 1 && b == 3)) {
    pa++;
    times++;
    get(choiceA[a][b], choiceB[a][b], pa, pb, times);
  } else {
    pb++;
    times++;
    get(choiceA[a][b], choiceB[a][b], pa, pb, times);
  }
}
void get2(int a, int b, long long &pa, long long &pb, long long &times) {
  if (times > k) {
    times--;
    return;
  }
  if (a == b) {
    times++;
    get2(choiceA[a][b], choiceB[a][b], pa, pb, times);
    return;
  }
  if ((a == 3 && b == 2) || (a == 2 && b == 1) || (a == 1 && b == 3)) {
    pa++;
    times++;
    get2(choiceA[a][b], choiceB[a][b], pa, pb, times);
  } else {
    pb++;
    times++;
    get2(choiceA[a][b], choiceB[a][b], pa, pb, times);
  }
}
int main() {
  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", &choiceA[i][j]);
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      scanf("%d", &choiceB[i][j]);
    }
  }
  long long pa = 0, pb = 0;
  long long times = 1;
  get(a, b, pa, pb, times);
  if (times == k) {
    printf("%lld %lld\n", pa, pb);
    return 0;
  }
  k -= times;
  pa += A * (k / (TIMES));
  pb += B * (k / (TIMES));
  k = k % (TIMES);
  times = 1;
  get2(statea, stateb, pa, pb, times);
  printf("%lld %lld", pa, pb);
  return 0;
}
