#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 100;
const long long int inf = 1e12;
long long int ans, res, curr, k, a, b, ans1, ans2, idx, temp, rem;
long long int arr[4][4], brr[4][4];
long long int mark[4][4];
vector<pair<long long int, long long int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> arr[i][j];
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) cin >> brr[i][j];
  curr = 1;
  while (curr <= k && !mark[a][b]) {
    mark[a][b] = curr++;
    if ((a == 3 && b == 2) || (a == 2 && b == 1) || (a == 1 && b == 3)) ans++;
    if ((b == 3 && a == 2) || (b == 2 && a == 1) || (b == 1 && a == 3)) res++;
    v.push_back(make_pair(a, b));
    idx = a;
    a = arr[a][b];
    b = brr[idx][b];
  }
  if (curr == (k + 1)) return cout << ans << " " << res << endl, 0;
  idx = mark[a][b] - 1;
  for (int i = idx; i < v.size(); i++) {
    if ((v[i].first == 3 && v[i].second == 2) ||
        (v[i].first == 2 && v[i].second == 1) ||
        (v[i].first == 1 && v[i].second == 3))
      ans1++;
    if ((v[i].first == 2 && v[i].second == 3) ||
        (v[i].first == 1 && v[i].second == 2) ||
        (v[i].first == 3 && v[i].second == 1))
      ans2++;
  }
  temp = v.size() - idx;
  rem = (k - curr) % temp;
  temp = (k - curr) / temp;
  ans1 *= temp, ans2 *= temp;
  for (int i = idx; i <= idx + rem; i++) {
    if ((v[i].first == 3 && v[i].second == 2) ||
        (v[i].first == 2 && v[i].second == 1) ||
        (v[i].first == 1 && v[i].second == 3))
      ans1++;
    if ((v[i].first == 2 && v[i].second == 3) ||
        (v[i].first == 1 && v[i].second == 2) ||
        (v[i].first == 3 && v[i].second == 1))
      ans2++;
  }
  ans += ans1;
  res += ans2;
  cout << ans << " " << res << endl;
  return 0;
}
