#include <bits/stdc++.h>
using namespace std;
int a, b, na, nb, vs[3][3];
int awin[10], bwin[10];
int A[3][3], B[3][3];
long long k, ansa, ansb;
int main() {
  cin >> k >> a >> b;
  a--;
  b--;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> B[i][j];
      B[i][j]--;
    }
  }
  for (int i = 1; i <= k; i++) {
    if (vs[a][b] == 0) {
      vs[a][b] = i;
      awin[i] = awin[i - 1];
      bwin[i] = bwin[i - 1];
      if (a == (b + 1) % 3) awin[i]++;
      if (b == (a + 1) % 3) bwin[i]++;
      if (i == k) {
        ansa = awin[i];
        ansb = bwin[i];
      } else {
        na = A[a][b];
        nb = B[a][b];
        a = na;
        b = nb;
      }
    } else {
      ;
      long long loop = i - vs[a][b];
      long long rep = (k - vs[a][b]) / loop;
      k -= rep * loop;
      ansa = rep * (awin[i - 1] - awin[vs[a][b] - 1]) + awin[k];
      ansb = rep * (bwin[i - 1] - bwin[vs[a][b] - 1]) + bwin[k];
      break;
    }
  }
  cout << ansa << " " << ansb << endl;
  return 0;
}
