#include <bits/stdc++.h>
long long k, suma, sumb;
int fa[4][4], fb[4][4], g[4][4], a, b;
struct note {
  long long i, a, b;
} f[4][4];
int main() {
  g[3][2] = 1;
  g[2][1] = 1;
  g[1][3] = 1;
  scanf("%lld", &k);
  scanf("%d%d", &a, &b);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &fa[i][j]);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &fb[i][j]);
  long long i = 0;
  while (!f[a][b].i && i < k) {
    int t = a;
    i++;
    f[a][b].a = suma;
    f[a][b].b = sumb;
    suma += g[a][b];
    sumb += g[b][a];
    f[a][b].i = i;
    a = fa[a][b];
    b = fb[t][b];
  }
  if (i < k) {
    i++;
    long long t = (k - f[a][b].i) / (i - f[a][b].i) - 1,
              m = (k - f[a][b].i) % (i - f[a][b].i) + 1;
    suma += t * (suma - f[a][b].a);
    sumb += t * (sumb - f[a][b].b);
    for (int i = 1; i <= m; i++) {
      int t = a;
      suma += g[a][b];
      sumb += g[b][a];
      a = fa[a][b];
      b = fb[t][b];
    }
  }
  printf("%lld %lld", suma, sumb);
}
