#include <bits/stdc++.h>
using namespace std;
struct m {
  int a, b;
} mbuf;
int isin(const vector<m> &h, const int a, const int b) {
  for (int i = h.size() - 1; i >= 0; i--) {
    if (h[i].a == a && h[i].b == b) return i;
  }
  return -1;
}
void pp(int a, int b, unsigned long long &ap, unsigned long long &bp) {
  switch (a - b) {
    case 1:
      ap++;
      break;
    case 2:
      bp++;
      break;
    case -1:
      bp++;
      break;
    case -2:
      ap++;
  }
}
void solve() {
  unsigned long long k, ap, bp;
  k = 1;
  ap = bp = 0;
  int a, b, A[3][3], B[3][3];
  cin >> k >> a >> b;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      cin >> B[i][j];
    }
  vector<m> h;
  int pos = -1;
  for (unsigned long long i = 0; i < k && pos < 0; i++) {
    mbuf.a = a;
    mbuf.b = b;
    h.push_back(mbuf);
    pp(a, b, ap, bp);
    a = A[mbuf.a - 1][mbuf.b - 1];
    b = B[mbuf.a - 1][mbuf.b - 1];
    pos = isin(h, a, b);
  }
  if (pos >= 0) {
    unsigned long long q = (k - pos) / (h.size() - pos),
                       r = (k - pos) % (h.size() - pos);
    if (--q > 0) {
      unsigned long long da = 0, db = 0;
      for (int i = pos; i < h.size(); i++) pp(h[i].a, h[i].b, da, db);
      ap += q * da;
      bp += q * db;
    }
    for (int i = pos; i < pos + r; i++) pp(h[i].a, h[i].b, ap, bp);
  }
  cout << ap << ' ' << bp;
}
int main() {
  solve();
  return 0;
}
