#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int a[3][3], b[3][3], v[3][3], ai, bi;
long long k, aw, bw, ac, bc, i;
int win(int a, int b) {
  if (a == 1 && b == 3)
    return 1;
  else if (a == 3 && b == 1)
    return -1;
  else if (a == b)
    return 0;
  else if (a > b)
    return 1;
  else
    return -1;
}
vector<pair<int, int>> plays;
int main() {
  cin >> k >> ai >> bi;
  for (int x = 0; x < int(3); x++)
    for (int y = 0; y < int(3); y++) {
      scanf("%d", &a[x][y]);
    }
  for (int x = 0; x < int(3); x++)
    for (int y = 0; y < int(3); y++) {
      scanf("%d", &b[x][y]);
    }
  for (; k > 0; k--) {
    if (v[ai - 1][bi - 1]) break;
    aw += win(ai, bi) == 1;
    bw += win(ai, bi) == -1;
    plays.push_back({ai, bi});
    v[ai - 1][bi - 1] = 1;
    int tmp = a[ai - 1][bi - 1];
    bi = b[ai - 1][bi - 1];
    ai = tmp;
  }
  if (k) {
    for (; i < plays.size() && plays[i] != make_pair(ai, bi); i++)
      ;
    for (int j = i; j < plays.size(); j++) {
      ac += win(plays[j].first, plays[j].second) == 1;
      bc += win(plays[j].first, plays[j].second) == -1;
    }
    aw += ac * (k / (plays.size() - i));
    bw += bc * (k / (plays.size() - i));
    for (int j = 0; j < k % (plays.size() - i); j++) {
      aw += win(plays[i + j].first, plays[i + j].second) == 1;
      bw += win(plays[i + j].first, plays[i + j].second) == -1;
    }
  }
  cout << aw << " " << bw;
}
