#include <bits/stdc++.h>
using namespace std;
set<pair<int, pair<int, int> > > chosen;
set<pair<int, pair<int, int> > >::iterator it;
vector<pair<int, int> > step;
int find(int a, int b) {
  it = chosen.lower_bound(make_pair(a, make_pair(b, 0)));
  if (it == chosen.end()) return -1;
  if (it->first == a && it->second.first == b) {
    return it->second.second;
  }
  return -1;
}
int score(int a, int b) {
  if (a == b) return 0;
  if (a == 3 && b == 2) return 1;
  if (a == 2 && b == 1) return 1;
  if (a == 1 && b == 3) return 1;
  return 0;
}
int main() {
  long long k, scoreAlice = 0, scoreBob = 0;
  int a, b, A[4][4], B[4][4], loopFrom, index, loopScoreAlice = 0,
                                               loopScoreBob = 0;
  int ta, tb;
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++) {
    cin >> A[i][1] >> A[i][2] >> A[i][3];
  }
  for (int i = 1; i <= 3; i++) {
    cin >> B[i][1] >> B[i][2] >> B[i][3];
  }
  index = find(a, b);
  while (index == -1) {
    chosen.insert(make_pair(a, make_pair(b, step.size())));
    step.push_back(make_pair(a, b));
    ta = A[a][b];
    tb = B[a][b];
    a = ta;
    b = tb;
    index = find(a, b);
  }
  loopFrom = index;
  for (int i = 0; i < loopFrom; i++, k--) {
    if (k == 0) break;
    scoreAlice += score(step[i].first, step[i].second);
    scoreBob += score(step[i].second, step[i].first);
  }
  for (int i = loopFrom; i < step.size(); i++) {
    loopScoreAlice += score(step[i].first, step[i].second);
    loopScoreBob += score(step[i].second, step[i].first);
  }
  long long totalLoop = k / (step.size() - loopFrom);
  scoreAlice += loopScoreAlice * totalLoop;
  scoreBob += loopScoreBob * totalLoop;
  k = k % (step.size() - loopFrom);
  for (int i = loopFrom; i < step.size(); i++, k--) {
    if (k == 0) break;
    scoreAlice += score(step[i].first, step[i].second);
    scoreBob += score(step[i].second, step[i].first);
  }
  cout << scoreAlice << " " << scoreBob << endl;
  return 0;
}
