#include <bits/stdc++.h>
using namespace std;
long long nex[9], val[9];
long long k, a, b;
long long A[3][3], B[3][3];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> k >> a >> b;
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 3; j++) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 3; j++) {
      cin >> B[i][j];
      B[i][j]--;
    }
  }
  for (long long i = 0; i < 9; i++) {
    long long x = i / 3, y = i % 3;
    if (x == y)
      val[i] = -1;
    else {
      if ((x == 0 and y == 2) or (x == 1 and y == 0) or (x == 2 and y == 1)) {
        val[i] = 0;
      } else
        val[i] = 1;
    }
    long long nx = A[x][y], ny = B[x][y];
    nex[i] = nx * 3 + ny;
  }
  a--, b--;
  vector<bool> vis(9, 0);
  long long start = 3 * a + b;
  long long alice = 0, bob = 0;
  while (!vis[start]) {
    vis[start] = 1;
    if (k == 0) {
      break;
    }
    if (val[start] == 0) alice++;
    if (val[start] == 1) bob++;
    start = nex[start];
    k--;
  }
  if (k == 0) {
    cout << alice << " " << bob << '\n';
    return 0;
  }
  long long len = 0;
  long long t = start;
  long long a1 = 0, b1 = 0;
  do {
    if (val[t] == 0) a1++;
    if (val[t] == 1) b1++;
    len++;
    t = nex[t];
  } while (t != start);
  t = k / len;
  long long r = k % len;
  alice += t * a1;
  bob += t * b1;
  while (r--) {
    if (val[start] == 0) alice++;
    if (val[start] == 1) bob++;
    start = nex[start];
  }
  cout << alice << " " << bob << '\n';
}
