#include <bits/stdc++.h>
using namespace std;
int ab[4][4];
int ba[4][4];
bool pan[4][4];
long long sum1, sum2, pp, bb;
void add(int a, int b);
void add2(int a, int b);
int main() {
  long long n, k, a, b, i, j, temp1, temp2, cur, c, d, m;
  bool flag;
  cin >> k >> a >> b;
  for (i = 1; i <= 3; ++i)
    for (j = 1; j <= 3; ++j) cin >> ab[i][j];
  for (i = 1; i <= 3; ++i)
    for (j = 1; j <= 3; ++j) cin >> ba[i][j];
  flag = true;
  temp1 = a;
  temp2 = b;
  memset(pan, false, sizeof(pan));
  pan[a][b] = true;
  sum1 = sum2 = 0;
  add(a, b);
  n = 1;
  pp = bb = 0;
  cur = 0;
  k--;
  while (k) {
    a = ab[temp1][temp2];
    b = ba[temp1][temp2];
    temp1 = a;
    temp2 = b;
    if (pan[a][b] == true) {
      c = a;
      d = b;
      cur = 0;
      do {
        add2(a, b);
        a = ab[temp1][temp2];
        b = ba[temp1][temp2];
        temp1 = a;
        temp2 = b;
        cur++;
      } while (a != c || b != d);
      break;
    }
    k--;
    add(a, b);
    pan[a][b] = true;
  }
  if (k != 0) {
    sum1 += k / cur * bb;
    sum2 += k / cur * pp;
    k %= cur;
  }
  for (; k > 0;) {
    add(a, b);
    a = ab[temp1][temp2];
    b = ba[temp1][temp2];
    temp1 = a;
    temp2 = b;
    k--;
  }
  cout << sum1 << " " << sum2 << endl;
}
void add(int a, int b) {
  if (a == 3 && b == 1) {
    sum2++;
    return;
  } else if (b == 3 && a == 1) {
    sum1++;
    return;
  }
  if (a > b)
    sum1++;
  else if (b > a)
    sum2++;
}
void add2(int a, int b) {
  if (a == 3 && b == 1) {
    pp++;
    return;
  }
  if (b == 3 && a == 1) {
    bb++;
    return;
  }
  if (a > b)
    bb++;
  else if (b > a)
    pp++;
  return;
}
