#include <bits/stdc++.h>
using namespace std;
long long win(long long x, long long y) {
  return ((x == 3 and y == 2) or (x == 2 and y == 1) or (x == 1 and y == 3));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long k, a, b, k1;
  cin >> k1 >> a >> b;
  k = k1;
  long long al[4][4], bo[4][4];
  for (long long i = 0; i < (3); i++)
    for (long long j = 0; j < (3); j++) cin >> al[i + 1][j + 1];
  for (long long i = 0; i < (3); i++)
    for (long long j = 0; j < (3); j++) cin >> bo[i + 1][j + 1];
  vector<pair<long long, long long> > v;
  set<pair<long long, long long> > st;
  while (st.find(make_pair(a, b)) == st.end()) {
    v.push_back(make_pair(a, b));
    st.insert(make_pair(a, b));
    long long a1 = al[a][b];
    long long b1 = bo[a][b];
    a = a1;
    b = b1;
  }
  long long sz = v.size(), r1, r2;
  for (long long i = 0; i < (sz); i++) {
    if (v[i] == make_pair(a, b)) {
      r1 = i;
      break;
    }
  }
  r2 = sz - 1;
  long long ans = 0, cur = 0, ans2 = 0, cur2 = 0;
  for (long long i = 0; i < (min(sz, k)); i++) {
    if (win(v[i].first, v[i].second)) {
      ans++;
      if (i >= r1) cur++;
    }
    if (win(v[i].second, v[i].first)) {
      ans2++;
      if (i >= r1) cur2++;
    }
  }
  k -= min(sz, k);
  if (k != 0) {
    long long times = k / (r2 - r1 + 1);
    ans += times * cur;
    ans2 += times * cur2;
    k %= (r2 - r1 + 1);
    for (long long i = 0; i < (k); i++) {
      if (win(v[r1 + i].first, v[r1 + i].second)) {
        ans++;
      }
      if (win(v[r1 + i].second, v[r1 + i].first)) {
        ans2++;
      }
    }
  }
  cout << ans << " " << ans2 << endl;
}
