#include <bits/stdc++.h>
using namespace std;
int A[3][3], B[3][3], D[3][3], pa[101], pb[101];
int main() {
  long long k, a, b;
  cin >> k >> 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 = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) D[i][j] = -1;
  a--, b--;
  long long c = 1, ca = 0, cb = 0, i, j;
  for (i = a, j = b; D[i][j] == -1; ++c) {
    D[i][j] = c;
    ca += ((i - j == 1) || (j - i == 2));
    cb += ((j - i == 1) || (i - j == 2));
    pa[c] = ca;
    pb[c] = cb;
    int ix = A[i][j], jx = B[i][j];
    i = ix, j = jx;
  }
  long long k1 = D[i][j], k2 = c, m = k2 - k1;
  ca -= pa[k1 - 1], cb -= pb[k1 - 1];
  long long l = max(0ll, (k - k1) / m);
  long long ansa = l * ca, ansb = l * cb;
  k -= l * m;
  for (i = a, j = b; k > 0; --k) {
    ansa += ((i - j == 1) || (j - i == 2));
    ansb += ((j - i == 1) || (i - j == 2));
    int ix = A[i][j], jx = B[i][j];
    i = ix, j = jx;
  }
  cout << ansa << ' ' << ansb << '\n';
  return 0;
}
