#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long k, a, b;
  cin >> k >> a >> b;
  long long p[4][4], q[4][4], visit[4][4], c[20][2], i = 1;
  for (int i = (1); i <= (3); ++i)
    for (int j = (1); j <= (3); ++j) cin >> p[i][j];
  for (int i = (1); i <= (3); ++i)
    for (int j = (1); j <= (3); ++j) cin >> q[i][j];
  memset(visit, 0, sizeof visit);
  c[0][0] = c[0][1] = 0;
  long long ans1 = 0, ans2 = 0, flag = 0;
  while (1) {
    if (i > k) {
      flag = 1;
      break;
    }
    if (visit[a][b]) break;
    if (a == 1 && b == 2)
      ans2++;
    else if (a == 1 && b == 3)
      ans1++;
    else if (a == 2 && b == 1)
      ans1++;
    else if (a == 2 && b == 3)
      ans2++;
    else if (a == 3 && b == 1)
      ans2++;
    else if (a == 3 && b == 2)
      ans1++;
    c[i][0] = ans1, c[i][1] = ans2;
    visit[a][b] = i++;
    long long m = p[a][b];
    long long n = q[a][b];
    a = m, b = n;
  }
  if (flag == 1) {
    cout << ans1 << " " << ans2;
    return 0;
  }
  k -= visit[a][b] - 1;
  long long s = k / (i - visit[a][b]);
  long long r = k % (i - visit[a][b]);
  long long res1 = c[visit[a][b] - 1][0] +
                   s * (c[i - 1][0] - c[visit[a][b] - 1][0]) +
                   (c[visit[a][b] + r - 1][0] - c[visit[a][b] - 1][0]);
  long long res2 = c[visit[a][b] - 1][1] +
                   s * (c[i - 1][1] - c[visit[a][b] - 1][1]) +
                   (c[visit[a][b] + r - 1][1] - c[visit[a][b] - 1][1]);
  cout << res1 << " " << res2;
  return 0;
}
