#include <bits/stdc++.h>
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
void file() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int alice[4][4], bob[4][4];
int whoWin(int a, int b) {
  if (a == 1 && b == 3) return 1;
  if (a == 3 && b == 2) return 1;
  if (a == 2 && b == 1) return 1;
  if (b == 1 && a == 3) return 2;
  if (b == 3 && a == 2) return 2;
  if (b == 2 && a == 1) return 2;
  return 0;
}
int main() {
  file();
  long long n, a, b;
  cin >> n >> a >> b;
  for (int i = 1; i <= 3; i++)
    for (int k = 1; k <= 3; k++) cin >> alice[i][k];
  for (int i = 1; i <= 3; i++)
    for (int k = 1; k <= 3; k++) cin >> bob[i][k];
  map<pair<int, int>, pair<long long, pair<long long, long long> > > mp;
  long long cnta = 0, cntb = 0;
  for (long long i = 1; i <= n; i++) {
    if (whoWin(a, b) == 1) {
      cnta++;
    } else if (whoWin(a, b) == 2) {
      cntb++;
    }
    if (mp.find({a, b}) != mp.end()) {
      long long len = i - mp[{a, b}].first;
      long long turns = (n - i) / len;
      cnta += (cnta - mp[{a, b}].second.first) * turns;
      cntb += (cntb - mp[{a, b}].second.second) * turns;
      i += turns * len;
    } else {
      mp[{a, b}] = {i, {cnta, cntb}};
    }
    int tempa = a;
    a = alice[a][b];
    b = bob[tempa][b];
  }
  cout << cnta << " " << cntb << endl;
}
