#include <bits/stdc++.h>
using namespace std;
long long k;
int a, b;
long long ap, bp;
int ar[3][3];
int br[3][3];
bool visited[3][3];
long long aap, bap;
void update(int x, int y) {
  if (x == 1 && y == 2) {
    bp++;
    bap++;
  }
  if (x == 1 && y == 3) {
    ap++;
    aap++;
  }
  if (x == 2 && y == 1) {
    ap++;
    aap++;
  }
  if (x == 2 && y == 3) {
    bp++;
    bap++;
  }
  if (x == 3 && y == 1) {
    bp++;
    bap++;
  }
  if (x == 3 && y == 2) {
    ap++;
    aap++;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  aap = 0;
  bap = 0;
  cin >> k >> a >> b;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) cin >> ar[i][j];
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) cin >> br[i][j];
  }
  int ca = a, cb = b;
  long long tlength = 0;
  while (!visited[ca - 1][cb - 1]) {
    tlength++;
    visited[ca - 1][cb - 1] = 1;
    update(ca, cb);
    if (tlength == k) break;
    int cca = ca, ccb = cb;
    cca = ar[ca - 1][cb - 1];
    ccb = br[ca - 1][cb - 1];
    ca = cca;
    cb = ccb;
  }
  long long cyc = 2520;
  aap = 0;
  bap = 0;
  for (int i = 0; i < min(k - tlength, cyc); i++) {
    update(ca, cb);
    int cca = ca, ccb = cb;
    cca = ar[ca - 1][cb - 1];
    ccb = br[ca - 1][cb - 1];
    ca = cca;
    cb = ccb;
  }
  if (cyc > k - tlength) {
    cout << ap << " " << bp << "\n";
    return 0;
  }
  long long numCycles = (k - tlength) / cyc - 1;
  ap += numCycles * aap;
  bp += numCycles * bap;
  for (int i = 0; i < k - tlength - numCycles * cyc - cyc; i++) {
    update(ca, cb);
    int cca = ca, ccb = cb;
    cca = ar[ca - 1][cb - 1];
    ccb = br[ca - 1][cb - 1];
    ca = cca;
    cb = ccb;
  }
  cout << ap << " " << bp << "\n";
}
