#include <bits/stdc++.h>
using namespace std;
long long a[4][4], b[4][4], aa, bb;
long long k;
map<pair<long long, long long>, pair<long long, long long> > mpi;
map<pair<long long, long long>, long long> xuh;
pair<long long, long long> fssc[50];
long long firstxh, lastxh;
pair<long long, long long> zjscore, stscore;
int main() {
  scanf("%I64d%I64d%I64d", &k, &aa, &bb);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%I64d", a[i] + j);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%I64d", b[i] + j);
  xuh[make_pair(aa, bb)] = 1;
  pair<long long, long long> score = make_pair(0, 0);
  if ((aa == 3 && bb == 2) || (aa == 2 && bb == 1) || (aa == 1 && bb == 3))
    score.first++;
  if ((bb == 3 && aa == 2) || (bb == 2 && aa == 1) || (bb == 1 && aa == 3))
    score.second++;
  mpi[make_pair(aa, bb)] = score;
  fssc[1] = score;
  long long i;
  for (i = 2; i <= k; i++) {
    long long maa = aa, mbb = bb;
    aa = a[maa][mbb];
    bb = b[maa][mbb];
    if ((aa == 3 && bb == 2) || (aa == 2 && bb == 1) || (aa == 1 && bb == 3))
      score.first++;
    if ((bb == 3 && aa == 2) || (bb == 2 && aa == 1) || (bb == 1 && aa == 3))
      score.second++;
    fssc[i] = score;
    if (xuh.count(make_pair(aa, bb))) {
      firstxh = xuh[make_pair(aa, bb)];
      lastxh = i;
      pair<long long, long long> sc = mpi[make_pair(aa, bb)];
      zjscore = make_pair(score.first - sc.first, score.second - sc.second);
      stscore = sc;
      break;
    }
    xuh[make_pair(aa, bb)] = i;
    mpi[make_pair(aa, bb)] = score;
  }
  if (i <= k) {
    long long xhnum = lastxh - firstxh;
    long long chu = (k - firstxh) / (xhnum), mo = (k - firstxh) % (xhnum);
    score.first = chu * zjscore.first + fssc[mo + firstxh].first;
    score.second = chu * zjscore.second + fssc[mo + firstxh].second;
  }
  printf("%I64d %I64d\n", score.first, score.second);
  return 0;
}
