#include <bits/stdc++.h>
using namespace std;
const int N = 4;
int mp[N][N], len, a, b, aa, bb, A[N][N], B[N][N], tot, i, j, q[1007];
long long sum1, sum2, k, ans1, ans2, tmp;
int go(int x, int y) {
  if (x == 1 && y == 2 || x == 2 && y == 3 || x == 3 && y == 1)
    return -1;
  else if (x == y)
    return 0;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (cin >> k >> a >> b, i = 1; i <= 3; ++i)
    for (j = 1; j <= 3; ++j) cin >> A[i][j];
  for (i = 1; i <= 3; ++i)
    for (j = 1; j <= 3; ++j) cin >> B[i][j];
  while (true) {
    if (mp[a][b] == 2) break;
    q[++len] = go(a, b);
    mp[a][b]++;
    aa = A[a][b];
    bb = B[a][b];
    a = aa;
    b = bb;
  }
  if (k <= len) {
    for (i = 1; i <= k; ++i) {
      if (q[i] > 0) ans1++;
      if (q[i] < 0) ans2++;
    }
    cout << ans1 << " " << ans2 << endl;
  } else {
    for (i = 1; i <= 3; ++i)
      for (j = 1; j <= 3; ++j)
        if (mp[i][j] == 2) tot++;
    for (i = 1; i <= len; ++i) {
      if (q[i] > 0) ans1++;
      if (q[i] < 0) ans2++;
    }
    for (i = len - tot + 1; i <= len; ++i) {
      if (q[i] > 0) sum1++;
      if (q[i] < 0) sum2++;
    }
    k -= len;
    tmp = k / tot;
    k %= tot;
    for (i = len - tot + 1; i < len - tot + 1 + k; ++i) {
      if (q[i] > 0) ans1++;
      if (q[i] < 0) ans2++;
    }
    cout << ans1 + tmp * sum1 << " " << ans2 + tmp * sum2 << endl;
  }
  return 0;
}
