#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int k, i, j, ptsa, ptsb, a, b, tmp, len, ptfromlen;
  cin >> k >> a >> b;
  a--;
  b--;
  int ali[3][3], bob[3][3];
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      scanf("%d", &ali[i][j]);
      ali[i][j]--;
    }
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      scanf("%d", &bob[i][j]);
      bob[i][j]--;
    }
  }
  int lastpos[3][3];
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) lastpos[i][j] = -1;
  }
  ptsa = ptsb = 0;
  vector<long long int> awala;
  vector<long long int> bwala;
  i = 0;
  while (lastpos[a][b] == -1) {
    if (a == b)
      ;
    else if (a == 2) {
      if (b == 1)
        ptsa++;
      else
        ptsb++;
    } else if (a == 1) {
      if (b == 0)
        ptsa++;
      else
        ptsb++;
    } else {
      if (b == 2)
        ptsa++;
      else
        ptsb++;
    }
    awala.push_back(ptsa);
    bwala.push_back(ptsb);
    tmp = a;
    lastpos[a][b] = i;
    a = ali[a][b];
    b = bob[tmp][b];
    i++;
  }
  if (i >= k)
    cout << awala[k - 1] << " " << bwala[k - 1];
  else {
    j = lastpos[a][b];
    if (j == 0)
      ptsa = ptsb = 0;
    else {
      ptsa = awala[j - 1];
      ptsb = bwala[j - 1];
    }
    len = i - j;
    k -= j;
    if (j == 0)
      ptfromlen = awala[i - 1];
    else
      ptfromlen = awala[i - 1] - awala[j - 1];
    ptsa += ptfromlen * (k / len);
    if (j == 0) {
      if (k % len != 0) ptsa += awala[k % len - 1];
    } else
      ptsa += awala[k % len + j - 1] - awala[j - 1];
    if (j == 0)
      ptfromlen = bwala[i - 1];
    else
      ptfromlen = bwala[i - 1] - bwala[j - 1];
    ptsb += ptfromlen * (k / len);
    if (j == 0) {
      if (k % len != 0) ptsb += bwala[k % len - 1];
    } else
      ptsb += bwala[k % len + j - 1] - bwala[j - 1];
    cout << ptsa << " " << ptsb;
  }
  return 0;
}
