#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
long long n;
int x, y;
int a[5][5], b[5][5];
long long used[5][5];
int m = 3;
long long A, B;
long long aa, bb;
void update(int x, int y, int t) {
  x %= 3;
  y %= 3;
  if (x == (y + 1) % 3) {
    if (t)
      aa++;
    else
      A++;
  }
  if (y == (x + 1) % 3) {
    if (t)
      bb++;
    else
      B++;
  }
}
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }
  update(x, y, 0);
  used[x][y] = 1;
  long long sz = 1ll;
  while (sz != n) {
    int p = x, q = y;
    x = a[p][q];
    y = b[p][q];
    if (used[x][y] == 0) {
      used[x][y] = ++sz;
      update(x, y, 0);
    } else
      break;
  }
  if (sz == n) {
    cout << A << " " << B << endl;
    return 0;
  }
  long long len = 1ll * (sz - used[x][y] + 1);
  n -= sz;
  while (true) {
    update(x, y, 1);
    if (used[x][y] == sz) break;
    int p = x, q = y;
    x = a[p][q];
    y = b[p][q];
  }
  int p = x, q = y;
  x = a[p][q];
  y = b[p][q];
  long long gorc = n / len;
  A += gorc * aa;
  B += gorc * bb;
  n %= len;
  while (n--) {
    update(x, y, 0);
    int p = x, q = y;
    x = a[p][q];
    y = b[p][q];
  }
  cout << A << " " << B << endl;
  return 0;
}
