#include <bits/stdc++.h>
using namespace std;
int64_t a[4][4] = {0};
int64_t b[4][4] = {0};
int64_t chk(int64_t aa, int64_t bb) {
  if (aa == bb) return 0;
  if (aa == 3 && bb == 2) return 1;
  if (aa == 2 && bb == 1) return 1;
  if (aa == 1 && bb == 3) return 1;
  return 2;
}
int64_t ma[4][4] = {0};
signed main() {
  int64_t k, A, B;
  cin >> k >> A >> B;
  for (int64_t i = 1; i <= 3; ++i) {
    for (int64_t j = 1; j <= 3; ++j) cin >> a[i][j];
  }
  for (int64_t i = 1; i <= 3; ++i) {
    for (int64_t j = 1; j <= 3; ++j) cin >> b[i][j];
  }
  if (k <= 100 * 1000) {
    int64_t curr1 = A;
    int64_t curr2 = B;
    int64_t la = 0, lb = 0;
    int64_t score1 = 0;
    int64_t score2 = 0;
    int64_t len = 0;
    int64_t hey_a = -1, hey_b = -1;
    for (int64_t t = 1; t <= k; ++t) {
      if (chk(curr1, curr2) == 1)
        score1++;
      else if (chk(curr1, curr2) == 2)
        score2++;
      int64_t _c1 = curr1, _c2 = curr2;
      curr1 = a[_c1][_c2];
      curr2 = b[_c1][_c2];
    }
    cout << score1 << " " << score2 << "\n";
    return 0;
  }
  int64_t curr1 = A;
  int64_t curr2 = B;
  int64_t la = 0, lb = 0;
  int64_t score1 = 0;
  int64_t score2 = 0;
  int64_t len = 0;
  int64_t hey_a = -1, hey_b = -1;
  for (int64_t t = 1; t <= k; ++t) {
    if (ma[curr1][curr2] > 0) {
      hey_a = curr1, hey_b = curr2;
      len = t - ma[curr1][curr2];
      break;
    }
    ma[curr1][curr2] = t;
    int64_t _c1 = curr1, _c2 = curr2;
    curr1 = a[_c1][_c2];
    curr2 = b[_c1][_c2];
  }
  int64_t tstart = -1;
  int64_t cnt1 = 0;
  curr1 = A, curr2 = B;
  for (int64_t t = 1; t <= k; ++t) {
    if (curr1 == hey_a && curr2 == hey_b) {
      tstart = t;
      break;
    }
    cnt1++;
    if (chk(curr1, curr2) == 1)
      la++;
    else if (chk(curr1, curr2) == 2)
      lb++;
    int64_t _c1 = curr1, _c2 = curr2;
    curr1 = a[_c1][_c2];
    curr2 = b[_c1][_c2];
  }
  for (int64_t t = tstart; t <= k; ++t) {
    if (chk(curr1, curr2) == 1)
      score1++;
    else if (chk(curr1, curr2) == 2)
      score2++;
    int64_t _c1 = curr1, _c2 = curr2;
    curr1 = a[_c1][_c2];
    curr2 = b[_c1][_c2];
    if (curr1 == hey_a && curr2 == hey_b) {
      break;
    }
  }
  if (len > 0 && (k - cnt1) / len > 0) {
    score1 = ((k - cnt1) / len) * score1;
    score2 = ((k - cnt1) / len) * score2;
  }
  score1 += la;
  score2 += lb;
  int64_t rem = 0;
  if (len > 0) rem = (k - cnt1) % len;
  if (rem > 0) {
    curr1 = hey_a;
    curr2 = hey_b;
    while (rem--) {
      if (chk(curr1, curr2) == 1)
        score1++;
      else if (chk(curr1, curr2) == 2)
        score2++;
      int64_t _c1 = curr1, _c2 = curr2;
      curr1 = a[_c1][_c2];
      curr2 = b[_c1][_c2];
    }
  }
  cout << score1 << " " << score2 << "\n";
  return 0;
}
