#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
long long mul(long long a, long long b) { return (a * b) % (1000000007); }
long long add(long long a, long long b) { return (a + b) % (1000000007); }
long long sub(long long a, long long b) {
  return ((a - b) % (1000000007) + (1000000007)) % (1000000007);
}
void upd(long long &a, long long b) {
  a = (a % (1000000007) + b % (1000000007)) % (1000000007);
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int fa[100][100];
int fb[100][100];
int id(int x, int y) { return (x - 1) * 3 + y - 1; }
long long ro = 0, bk = 0;
long long h[1000] = {};
long long hro[1000], hbk[1000];
int main() {
  long long k;
  cin >> k;
  int a = read(), b = read();
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) fa[i][j] = read();
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) fb[i][j] = read();
  for (long long t = 1; t <= k; t++) {
    ro += (long long)(a == b);
    bk += (long long)((a + 1) % 3 == b % 3);
    int p = id(a, b);
    if (!h[p]) {
      h[p] = t;
      hro[p] = ro, hbk[p] = bk;
    } else if (k - t > 10) {
      long long len = t - h[p];
      long long c = (k - t) / len;
      ro += c * (ro - hro[p]);
      bk += c * (bk - hbk[p]);
      t += c * len;
    }
    int na = fa[a][b];
    int nb = fb[a][b];
    a = na, b = nb;
  }
  cout << k - ro - bk << ' ' << bk << endl;
  return 0;
}
