#include <bits/stdc++.h>
using namespace std;
long long Round;
const int N = 1e4;
long long sa[N], sb[N];
int game[555][555];
int nxt_a[4][4];
int nxt_b[4][4];
int call(int a, int b, int lvl) {
  if (game[a][b] or lvl == Round + 1) {
    int prev_lvl = game[a][b];
    int cycle_len = lvl - game[a][b];
    long long cycle_sa = sa[lvl - 1] - sa[prev_lvl - 1];
    long long cycle_sb = sb[lvl - 1] - sb[prev_lvl - 1];
    long long ans1 = sa[lvl - 1], ans2 = sb[lvl - 1];
    long long remaining_game = Round - lvl + 1;
    long long cyc_times = remaining_game / cycle_len;
    ans1 += cyc_times * cycle_sa;
    ans2 += cyc_times * cycle_sb;
    long long aro_baki = remaining_game % cycle_len;
    while (aro_baki--) {
      if ((a + 1) % 3 == b) {
        ans2++;
      } else if (a == (b + 1) % 3) {
        ans1++;
      }
      int a1 = nxt_a[a][b], b1 = nxt_b[a][b];
      a = a1;
      b = b1;
    }
    cout << ans1 << " " << ans2 << endl;
    exit(0);
  } else {
    game[a][b] = lvl;
    sa[lvl] = sa[lvl - 1];
    sb[lvl] = sb[lvl - 1];
    if ((a + 1) % 3 == b) {
      sb[lvl]++;
    } else if (a == (b + 1) % 3) {
      sa[lvl]++;
    }
    call(nxt_a[a][b], nxt_b[a][b], lvl + 1);
  }
}
int main() {
  int a, b;
  cin >> Round;
  cin >> a >> b;
  a--, b--;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> nxt_a[i][j];
      nxt_a[i][j]--;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> nxt_b[i][j];
      nxt_b[i][j]--;
    }
  }
  call(a, b, 1);
}
