#include <bits/stdc++.h>
using namespace std;
long long t1, t2, z, w, k, v1, v2, cnt;
int a, b, x, y;
int A[4][4], B[4][4], v[4][4];
int win(int a, int b) {
  if (a == 1 && b == 3) return 1;
  if (a - b == 1) return 1;
  return 0;
}
void solve() {
  while (v[a][b] == 0 && k > 0ll) {
    k--;
    v[a][b] = ++cnt;
    if (win(a, b)) v1++;
    if (win(b, a)) v2++;
    x = A[a][b];
    y = B[a][b];
    a = x;
    b = y;
  }
}
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]);
  solve();
  if (k == 0ll) {
    printf("%lld %lld\n", v1, v2);
    return 0;
  }
  memset(v, 0, sizeof(v));
  cnt = 0;
  t1 = v1;
  t2 = v2;
  v1 = 0;
  v2 = 0;
  solve();
  v1 *= (k / cnt + 1);
  v2 *= (k / cnt + 1);
  t1 += v1;
  t2 += v2;
  k %= cnt;
  memset(v, 0, sizeof(v));
  v1 = v2 = 0ll;
  solve();
  printf("%lld %lld\n", t1 + v1, t2 + v2);
  return 0;
}
