#include <bits/stdc++.h>
using namespace std;
int a[5][5], b[5][5], book[5][5];
long long p[105], n, q[105];
int main() {
  int x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> a[i][j];
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> b[i][j];
  memset(book, 0, sizeof book);
  int k = 0;
  while (!book[x][y]) {
    p[++k] = p[k - 1];
    q[k] = q[k - 1];
    if (x == 1 && y == 3) p[k]++;
    if (x == 2 && y == 1) p[k]++;
    if (x == 3 && y == 2) p[k]++;
    if (y == 1 && x == 3) q[k]++;
    if (y == 2 && x == 1) q[k]++;
    if (y == 3 && x == 2) q[k]++;
    book[x][y] = k;
    int xx = x, yy = y;
    x = a[xx][yy];
    y = b[xx][yy];
  }
  p[++k] = p[k - 1];
  q[k] = q[k - 1];
  if (x == 1 && y == 3) p[k]++;
  if (x == 2 && y == 1) p[k]++;
  if (x == 3 && y == 2) p[k]++;
  if (y == 1 && x == 3) q[k]++;
  if (y == 2 && x == 1) q[k]++;
  if (y == 3 && x == 2) q[k]++;
  int j = book[x][y];
  long long len = k - j, ans1, ans2;
  if (n > k) {
    ans1 = (n - j) / len * (p[k] - p[j]) + p[j] + p[(n - j) % len + j] - p[j];
    ans2 = (n - j) / len * (q[k] - q[j]) + q[j] + q[(n - j) % len + j] - q[j];
  } else {
    ans1 = p[n];
    ans2 = q[n];
  }
  printf("%lld %lld\n", ans1, ans2);
  return 0;
}
