#include <bits/stdc++.h>
using namespace std;
long long k;
int a, b;
int win[4][4] = {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 0}};
int al[4][4];
int bo[4][4];
long long vis[4][4];
long long cycle_times;
long long cycle_score_of_a, cycle_score_of_b, cycle_a, cycle_b;
long long score_of_a, score_of_b;
long long front_score_of_a, front_score_of_b, front_times;
long long cycle_all_times;
long long back_score_a, back_score_b;
void all_have_add() {
  int i, j;
  for (i = 1; i < 4; i++) {
    for (j = 1; j < 4; j++) {
      if (vis[i][j] > 0) {
        vis[i][j]++;
      }
    }
  }
}
int next_a(int na, int nb) {
  int ra;
  ra = al[na][nb];
  return ra;
}
int next_b(int na, int nb) {
  int rb;
  rb = bo[na][nb];
  return rb;
}
void find_common() {
  long long i;
  int ta, tb, na, nb;
  memset(vis, 0, sizeof(vis));
  ta = a;
  tb = b;
  i = 0;
  while (vis[ta][tb] == 0) {
    if (i >= k) {
      cycle_times = -1;
      cycle_a = ta;
      cycle_b = tb;
      return;
    }
    all_have_add();
    if (vis[ta][tb] == 0) {
      vis[ta][tb] = 1;
    }
    na = next_a(ta, tb);
    nb = next_b(ta, tb);
    ta = na;
    tb = nb;
    i++;
  }
  cycle_times = vis[ta][tb];
  cycle_a = ta;
  cycle_b = tb;
  memset(vis, 0, sizeof(vis));
  while (vis[ta][tb] == 0) {
    vis[ta][tb] = 1;
    cycle_score_of_a += win[ta][tb];
    cycle_score_of_b += win[tb][ta];
    na = next_a(ta, tb);
    nb = next_b(ta, tb);
    ta = na;
    tb = nb;
  }
}
void front_score() {
  int i, ta, tb, na, nb;
  ta = a;
  tb = b;
  while (ta != cycle_a || tb != cycle_b) {
    front_times++;
    front_score_of_a += win[ta][tb];
    front_score_of_b += win[tb][ta];
    na = next_a(ta, tb);
    nb = next_b(ta, tb);
    ta = na;
    tb = nb;
  }
  score_of_a += front_score_of_a;
  score_of_b += front_score_of_b;
}
void add_score() {
  cycle_all_times = (k - front_times) / cycle_times;
  score_of_a += cycle_all_times * cycle_score_of_a;
  score_of_b += cycle_all_times * cycle_score_of_b;
}
void add_back_score() {
  int ta, tb, na, nb;
  long long start, i;
  start = front_times + cycle_all_times * cycle_times + 1;
  ta = cycle_a;
  tb = cycle_b;
  for (i = start; i <= k; i++) {
    back_score_a += win[ta][tb];
    back_score_b += win[tb][ta];
    na = next_a(ta, tb);
    nb = next_b(ta, tb);
    ta = na;
    tb = nb;
  }
  score_of_a += back_score_a;
  score_of_b += back_score_b;
}
int main() {
  long long i, j;
  int ta, tb, na, nb;
  cin >> k >> a >> b;
  for (i = 1; i <= 3; i++) {
    for (j = 1; j <= 3; j++) {
      cin >> al[i][j];
    }
  }
  for (i = 1; i <= 3; i++) {
    for (j = 1; j <= 3; j++) {
      cin >> bo[i][j];
    }
  }
  find_common();
  if (cycle_times == -1) {
    ta = a;
    tb = b;
    for (i = 1; i <= k; i++) {
      score_of_a += win[ta][tb];
      score_of_b += win[tb][ta];
      na = next_a(ta, tb);
      nb = next_b(ta, tb);
      ta = na;
      tb = nb;
    }
  } else {
    front_score();
    add_score();
    add_back_score();
  }
  cout << score_of_a << " " << score_of_b;
  return 0;
}
