#include <bits/stdc++.h>
using namespace std;
const int N = 1000007, inf = 0x3f3f3f3f;
int mata[10][10], matb[10][10];
int vis[10][10];
pair<long long, long long> dfs(int a, int b) {
  int c = mata[a][b];
  int d = matb[a][b];
  if (vis[c][d]) return make_pair(c, d);
  vis[c][d] = 1;
  return dfs(c, d);
}
int beats(int a, int b) { return (a == b % 3 + 1); }
pair<long long, long long> simulate(int a, int b, pair<long long, long long> t,
                                    long long& sz, int m = inf) {
  pair<long long, long long> ans = make_pair(0, 0);
  sz = 0;
  if (sz == m) return ans;
  while (1) {
    sz++;
    if (beats(a, b))
      ans.first++;
    else if (beats(b, a))
      ans.second++;
    if (sz == m) break;
    int c, d;
    c = mata[a][b];
    d = matb[a][b];
    a = c, b = d;
    if (a == t.first and b == t.second) break;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  long long k;
  int a, b;
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) {
      cin >> mata[i][j];
    }
  }
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) {
      cin >> matb[i][j];
    }
  }
  vis[a][b] = 1;
  pair<long long, long long> piv = dfs(a, b);
  long long l1, l2;
  pair<long long, long long> ans = simulate(a, b, piv, l1);
  if (l1 > k) {
    ans = simulate(a, b, piv, l1, k);
    cout << ans.first << " " << ans.second << endl;
    return 0;
  }
  k -= l1;
  pair<long long, long long> aux = simulate(piv.first, piv.second, piv, l2);
  long long p = k / l2;
  k = k % l2;
  aux.first *= p;
  aux.second *= p;
  ans.first += aux.first;
  ans.second += aux.second;
  aux = simulate(piv.first, piv.second, piv, l2, k);
  ans.first += aux.first;
  ans.second += aux.second;
  cout << ans.first << " " << ans.second << endl;
}
