#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 10;
pair<long long, pair<long long, long long>> done[4][4];
int nex[2][4][4];
long long n, a, b;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> a >> b;
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j < 4; j++) {
      for (int k = 1; k < 4; k++) {
        cin >> nex[i][j][k];
      }
    }
  }
  for (int i = 1; i < 4; i++) {
    for (int j = 1; j < 4; j++) {
      done[i][j].first = -1;
    }
  }
  long long alice = 0, bob = 0;
  long long nexa = a, nexb = b, pos = 1;
  while (done[nexa][nexb].first == -1 && n) {
    n--;
    if ((nexa) % 3 + 1 == nexb) {
      bob++;
    } else if (nexb % 3 + 1 == nexa) {
      alice++;
    }
    done[nexa][nexb] = {pos++, {alice, bob}};
    int locala = nexa, localb = nexb;
    nexa = nex[0][locala][localb];
    nexb = nex[1][locala][localb];
  }
  if (n == 0) {
    return cout << alice << ' ' << bob << endl, 0;
  }
  n--;
  if (nexa % 3 + 1 == nexb) {
    bob++;
  } else if (nexb % 3 + 1 == nexa) {
    alice++;
  }
  alice += (long long)(n / (pos - done[nexa][nexb].first)) *
           (alice - done[nexa][nexb].second.first);
  bob += (long long)(n / (pos - done[nexa][nexb].first)) *
         (bob - done[nexa][nexb].second.second);
  n %= (pos - done[nexa][nexb].first);
  int lla = nexa, llb = nexb;
  nexa = nex[0][lla][llb];
  nexb = nex[1][lla][llb];
  while (n--) {
    if ((nexa) % 3 + 1 == nexb) {
      bob++;
    } else if (nexb % 3 + 1 == nexa) {
      alice++;
    }
    int locala = nexa, localb = nexb;
    nexa = nex[0][locala][localb];
    nexb = nex[1][locala][localb];
  }
  cout << alice << ' ' << bob << endl;
  return 0;
}
