#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MOD = 1000000007;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long i, j, k[100], l, a, b, n, m, sum, maxx, minn, ans, sum1, x, y, flag,
    c, cc[4][4], dd[4][4], f[100], d[4][4], kk[100];
long long yi(long long x, long long y) {
  if (x == 3 && y == 2) return 1;
  if (x == 2 && y == 1) return 1;
  if (x == 1 && y == 3) return 1;
  return 0;
}
int main() {
  cin >> n >> a >> b;
  for (int i = (1); i < (4); i++)
    for (int j = (1); j < (4); j++) cc[i][j] = read();
  for (int i = (1); i < (4); i++)
    for (int j = (1); j < (4); j++) dd[i][j] = read();
  x = a;
  y = b;
  while (d[x][y] == 0 && c != n) {
    c++;
    d[x][y] = c;
    k[c] = yi(x, y);
    kk[c] = yi(y, x);
    sum += yi(x, y);
    sum1 += yi(y, x);
    long long u = x, t = y;
    x = cc[u][t];
    y = dd[u][t];
  }
  if (c == n) {
    cout << sum << " " << sum1 << endl;
    return 0;
  }
  ans = c - d[x][y] + 1;
  int q = 0, qq = 0;
  for (i = d[x][y]; i <= c; i++) {
    q += k[i];
    qq += kk[i];
  }
  sum += (n - c) / ans * q;
  sum1 += (n - c) / ans * qq;
  int e = (n - c) % ans;
  for (i = d[x][y], j = 0; j < e && i < c; i++, j++) {
    sum += k[i];
    sum1 += kk[i];
  }
  cout << sum << " " << sum1 << endl;
  return 0;
}
