#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e18;
long long int mod = (long long int)10e9 + 7;
double pi = 3.1415926535897932384626433832795;
long long int i, j;
long long int N = 1e5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<long long int> f, s;
  long long int k, kk, x, y, i, j;
  long long int c[4][4] = {0}, a[4][4], b[4][4], oa = 0, ob = 0, cou = 0,
                ooa = 0, oob = 0;
  cin >> k >> x >> y;
  kk = k;
  for (i = 1; i < 4; i++) {
    for (j = 1; j < 4; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i < 4; i++) {
    for (j = 1; j < 4; j++) {
      cin >> b[i][j];
    }
  }
  while (c[x][y] == 0 and k > 0) {
    cou++;
    f.push_back(x);
    s.push_back(y);
    if ((x == 3 and y == 2) or (x == 2 and y == 1) or (x == 1 and y == 3)) oa++;
    if ((x == 1 and y == 2) or (x == 2 and y == 3) or (x == 3 and y == 1)) ob++;
    c[x][y] = 1;
    i = x;
    j = y;
    x = a[i][j];
    y = b[i][j];
    k--;
  }
  long long int beg = 0, range;
  if (k == 0) {
    cout << oa << " " << ob << endl;
  } else {
    for (beg = 0;; beg++) {
      if (f[beg] == x and s[beg] == y) break;
    }
    range = f.size() - beg;
    i = beg;
    for (; i < f.size(); i++) {
      if ((f[i] == 3 and s[i] == 2) or (f[i] == 2 and s[i] == 1) or
          (f[i] == 1 and s[i] == 3))
        ooa++;
      if ((f[i] == 1 and s[i] == 2) or (f[i] == 2 and s[i] == 3) or
          (f[i] == 3 and s[i] == 1))
        oob++;
    }
    kk = k / range;
    k %= range;
    oa += ooa * kk;
    ob += oob * kk;
    i = beg;
    for (; i < beg + k; i++) {
      if ((f[i] == 3 and s[i] == 2) or (f[i] == 2 and s[i] == 1) or
          (f[i] == 1 and s[i] == 3))
        oa++;
      if ((f[i] == 1 and s[i] == 2) or (f[i] == 2 and s[i] == 3) or
          (f[i] == 3 and s[i] == 1))
        ob++;
    }
    cout << oa << " " << ob << endl;
  }
  return 0;
}
