#include <bits/stdc++.h>
using namespace std;
long long K;
int start_a, start_b;
int A[4][4], B[4][4];
int compare(int a, int b) {
  if (a == b) return 0;
  switch (a) {
    case 1:
      return b == 3 ? -1 : +1;
    case 2:
      return b == 1 ? -1 : +1;
    case 3:
      return b == 2 ? -1 : +1;
    default:
      assert(false);
  }
}
pair<long long, long long> solve() {
  int a = start_a, b = start_b;
  int period = -1, start_period = 0;
  vector<int> alice_score = {0};
  vector<int> bob_score = {0};
  vector<vector<int> > seen(4, vector<int>(4));
  for (int t = 1; t <= K; ++t) {
    fprintf(stderr, "(%d,%d)\n", a, b);
    if (seen[a][b]) {
      period = t - seen[a][b];
      start_period = seen[a][b];
      break;
    }
    seen[a][b] = t;
    int cmp = compare(a, b);
    alice_score.push_back(alice_score.back());
    bob_score.push_back(bob_score.back());
    if (cmp < 0)
      ++alice_score.back();
    else if (cmp > 0)
      ++bob_score.back();
    int nxt_a = A[a][b];
    int nxt_b = B[a][b];
    a = nxt_a;
    b = nxt_b;
  }
  if (period < 0) {
    return make_pair(alice_score.back(), bob_score.back());
  }
  fprintf(stderr, "start = %d  period = %d\n", start_period, period);
  pair<long long, long long> res =
      make_pair(alice_score[start_period - 1], bob_score[start_period - 1]);
  long long remK = K - start_period + 1;
  long long m = remK / period;
  fprintf(stderr, "remK: %lld  mult: %lld\n", remK, m);
  fprintf(stderr, "%d-%d  %d-%d\n", alice_score.back(),
          alice_score[start_period - 1], bob_score.back(),
          bob_score[start_period - 1]);
  res.first += m * (alice_score.back() - alice_score[start_period - 1]);
  res.second += m * (bob_score.back() - bob_score[start_period - 1]);
  remK -= m * period;
  fprintf(stderr, "remK: %lld\n", remK);
  res.first +=
      alice_score[start_period + remK - 1] - alice_score[start_period - 1];
  res.second +=
      bob_score[start_period + remK - 1] - bob_score[start_period - 1];
  return res;
}
int main(int argc, char* argv[]) {
  scanf("%lld %d %d", &K, &start_a, &start_b);
  for (int i = (1), _b = (3); i <= _b; ++i)
    for (int j = (1), _b = (3); j <= _b; ++j) scanf("%d", &A[i][j]);
  for (int i = (1), _b = (3); i <= _b; ++i)
    for (int j = (1), _b = (3); j <= _b; ++j) scanf("%d", &B[i][j]);
  auto res = solve();
  printf("%lld %lld\n", res.first, res.second);
  return 0;
}
