#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
const int MAXM = 100000;
const int INF = 0x3f3f3f3f;
pair<int, int> nxt[3][3];
int cot[3][3];
map<pair<int, int>, pair<long long, long long> > ma;
int main() {
  long long k;
  int a, b;
  scanf("%I64d%d%d", &k, &a, &b);
  a--, b--;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int x;
      scanf("%d", &x);
      x--;
      nxt[i][j].first = x;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int x;
      scanf("%d", &x);
      x--;
      nxt[i][j].second = x;
    }
  }
  pair<int, int> s = pair<int, int>(a, b);
  pair<long long, long long> now = pair<long long, long long>(0, 0);
  int cc = 0;
  while (ma.count(s) == 0) {
    if (k == 0) break;
    k--;
    cot[s.first][s.second] = cc++;
    ma[s] = now;
    if ((s.first + 1) % 3 == s.second)
      now.second++;
    else if (s.first == (1 + s.second) % 3)
      now.first++;
    s = nxt[s.first][s.second];
  }
  if (ma.count(s)) {
    pair<long long, long long> ans = now;
    now.first -= ma[s].first;
    now.second -= ma[s].second;
    long long lun = cc - cot[s.first][s.second];
    long long kk = k / lun;
    k %= lun;
    ans.first += now.first * kk;
    ans.second += now.second * kk;
    now = pair<long long, long long>(0, 0);
    while (k--) {
      if ((s.first + 1) % 3 == s.second)
        now.second++;
      else if (s.first == (1 + s.second) % 3)
        now.first++;
      s = nxt[s.first][s.second];
    }
    ans.first += now.first;
    ans.second += now.second;
    printf("%I64d %I64d\n", ans.first, ans.second);
  } else {
    s = nxt[s.first][s.second];
    printf("%I64d %I64d\n", now.first, now.second);
  }
}
