#include <bits/stdc++.h>
using namespace std;
long long int nextAlice[7][7];
long long int nextBob[7][7];
long long int nodeNum[7][7];
pair<long long int, long long int> curScore;
pair<long long int, long long int> cycScore;
pair<long long int, long long int> gameScore(long long int x, long long int y) {
  if (x == y) return make_pair(0, 0);
  if ((x == 3 && y == 2) || (x == 2 && y == 1) || (x == 1 && y == 3))
    return make_pair(1, 0);
  if ((y == 3 && x == 2) || (y == 2 && x == 1) || (y == 1 && x == 3))
    return make_pair(0, 1);
}
void addPair(pair<long long int, long long int> x) {
  curScore.first += x.first;
  curScore.second += x.second;
}
void addPairCyc(pair<long long int, long long int> x) {
  cycScore.first += x.first;
  cycScore.second += x.second;
}
int main() {
  long long int i, j, k, l, m, n, x, y, z, a, b, r, curnode, curAlice, curBob,
      tx, ty;
  scanf("%lld", &k);
  scanf("%lld", &a);
  scanf("%lld", &b);
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) scanf("%lld", &nextAlice[i][j]);
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) scanf("%lld", &nextBob[i][j]);
  curnode = 1;
  curAlice = a;
  curBob = b;
  while (nodeNum[curAlice][curBob] == 0) {
    x = curAlice;
    y = curBob;
    nodeNum[x][y] = curnode++;
    curAlice = nextAlice[x][y];
    curBob = nextBob[x][y];
  }
  x = curAlice;
  y = curBob;
  l = curnode - nodeNum[x][y];
  i = 0;
  curAlice = a;
  curBob = b;
  while (!(curAlice == x && curBob == y)) {
    tx = curAlice;
    ty = curBob;
    i++;
    if (i > k) {
      printf("%lld %lld\n", curScore.first, curScore.second);
      return 0;
    }
    addPair(gameScore(curAlice, curBob));
    curAlice = nextAlice[tx][ty];
    curBob = nextBob[tx][ty];
  }
  k = k - i;
  bool flag = true;
  curAlice = x;
  curBob = y;
  while (flag || !(curAlice == x && curBob == y)) {
    flag = false;
    tx = curAlice;
    ty = curBob;
    addPairCyc(gameScore(curAlice, curBob));
    curAlice = nextAlice[tx][ty];
    curBob = nextBob[tx][ty];
  }
  addPair(make_pair(k / l * cycScore.first, k / l * cycScore.second));
  k = k % l;
  curAlice = x;
  curBob = y;
  while (k > 0) {
    tx = curAlice;
    ty = curBob;
    addPair(gameScore(curAlice, curBob));
    curAlice = nextAlice[tx][ty];
    curBob = nextBob[tx][ty];
    k--;
  }
  printf("%lld %lld\n", curScore.first, curScore.second);
  return 0;
}
