#include <bits/stdc++.h>
using namespace std;
map<long long, map<long long, long long> > mp;
long long arr1[10][10], arr2[10][10], pref1[1000000], pref2[1000000];
int main() {
  long long k, a, b;
  cin >> k >> a >> b;
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < 3; j++) cin >> arr1[i][j];
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < 3; j++) cin >> arr2[i][j];
  long long d = 1;
  long long tot1 = 0, tot2 = 0;
  while (mp[a][b] == 0) {
    mp[a][b] = d;
    long long hi1 = a, hi2 = b;
    if (a == 3 && b == 2) tot1++;
    if (a == 2 && b == 1) tot1++;
    if (a == 1 && b == 3) tot1++;
    if (b == 3 && a == 2) tot2++;
    if (b == 2 && a == 1) tot2++;
    if (b == 1 && a == 3) tot2++;
    if (d == k) {
      cout << tot1 << " " << tot2;
      return 0;
    }
    a = arr1[hi1 - 1][hi2 - 1];
    b = arr2[hi1 - 1][hi2 - 1];
    pref1[d] = tot1;
    pref2[d] = tot2;
    d++;
  }
  d--;
  long long hi = d - mp[a][b] + 1;
  k -= d;
  long long l1 = pref1[d] - pref1[mp[a][b] - 1],
            l2 = pref2[d] - pref2[mp[a][b] - 1];
  l1 *= k / hi, l2 *= k / hi;
  tot1 += l1, tot2 += l2;
  k %= hi;
  while (k) {
    mp[a][b] = d;
    long long hi1 = a, hi2 = b;
    if (a == 3 && b == 2) tot1++;
    if (a == 2 && b == 1) tot1++;
    if (a == 1 && b == 3) tot1++;
    if (b == 3 && a == 2) tot2++;
    if (b == 2 && a == 1) tot2++;
    if (b == 1 && a == 3) tot2++;
    a = arr1[hi1 - 1][hi2 - 1];
    b = arr2[hi1 - 1][hi2 - 1];
    k--;
  }
  cout << tot1 << " " << tot2;
  return 0;
}
