#include <bits/stdc++.h>
using namespace std;
long long A[5][5], B[5][5];
map<pair<long long, long long>, long long> mpp;
int main() {
  long long k, a, b;
  cin >> k >> a >> b;
  long long i, j;
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) cin >> A[i][j];
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) cin >> B[i][j];
  set<pair<long long, long long> > s;
  long long cnta = 0, cntb = 0;
  long long x = a, y = b;
  i = 1;
  while (k > 0) {
    if (s.find(make_pair(x, y)) != s.end()) break;
    k--;
    mpp[make_pair(x, y)] = i;
    if (x == 3 && y == 2)
      cnta++;
    else if (y == 3 && x == 2)
      cntb++;
    else if (x == 1 && y == 3)
      cnta++;
    else if (y == 1 && x == 3)
      cntb++;
    else if (x == 2 && y == 1)
      cnta++;
    else if (y == 2 && x == 1)
      cntb++;
    s.insert(make_pair(x, y));
    a = A[x][y];
    b = B[x][y];
    x = a;
    y = b;
    i++;
  }
  if (k == 0) {
    cout << cnta << " " << cntb;
    return 0;
  }
  long long pos = mpp[make_pair(x, y)];
  a = x;
  b = y;
  long long diff = i - pos;
  long long t = k / diff;
  k = k % diff;
  long long tota = 0, totb = 0;
  for (j = pos; j < i; j++) {
    if (a == 3 && b == 2)
      tota++;
    else if (b == 3 && a == 2)
      totb++;
    else if (a == 1 && b == 3)
      tota++;
    else if (b == 1 && a == 3)
      totb++;
    else if (a == 2 && b == 1)
      tota++;
    else if (b == 2 && a == 1)
      totb++;
    long long a1 = A[a][b];
    long long b1 = B[a][b];
    a = a1;
    b = b1;
  }
  cnta = cnta + (t * tota);
  cntb = cntb + (t * totb);
  while (k > 0) {
    k--;
    if (x == 3 && y == 2)
      cnta++;
    else if (y == 3 && x == 2)
      cntb++;
    else if (x == 1 && y == 3)
      cnta++;
    else if (y == 1 && x == 3)
      cntb++;
    else if (x == 2 && y == 1)
      cnta++;
    else if (y == 2 && x == 1)
      cntb++;
    a = A[x][y];
    b = B[x][y];
    x = a;
    y = b;
  }
  cout << cnta << " " << cntb << "\n";
  return 0;
}
