#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k, a, b;
  int x[4][4], y[4][4];
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> x[i][j];
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> y[i][j];
  int r[1000];
  int check[4][4];
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) check[i][j] = 0;
  int sl = 0;
  int p = a, q = b;
  long long kq1 = 0, kq2 = 0;
  long midpoint;
  while (1) {
    if (check[p][q] == 0) {
      sl++;
      check[p][q] = sl;
    } else {
      midpoint = check[p][q];
      break;
    }
    if (p == q)
      r[sl] = 0;
    else if ((p == 3 && q == 2) || (p == 2 && q == 1) || (p == 1 && q == 3))
      r[sl] = 1;
    else
      r[sl] = -1;
    int tg1 = p, tg2 = q;
    p = x[tg1][tg2];
    q = y[tg1][tg2];
  }
  if (k < midpoint) {
    for (int i = 1; i <= k; i++) {
      if (r[i] == 1) kq1++;
      if (r[i] == -1) kq2++;
    }
  } else {
    for (int i = 1; i < midpoint; i++) {
      if (r[i] == 1) kq1++;
      if (r[i] == -1) kq2++;
    }
    k = k - midpoint + 1;
    long t1 = 0, t2 = 0;
    for (int i = midpoint; i <= sl; i++) {
      if (r[i] == 1) t1++;
      if (r[i] == -1) t2++;
    }
    long long thuong = k / (sl - midpoint + 1);
    long long du = k % (sl - midpoint + 1);
    kq1 += t1 * thuong;
    kq2 += t2 * thuong;
    for (int i = midpoint; i <= midpoint + du - 1; i++) {
      if (r[i] == 1) kq1++;
      if (r[i] == -1) kq2++;
    }
  }
  cout << kq1 << " " << kq2 << endl;
}
