#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
void f(int a, int b, long long &s1, long long &s2) {
  s2 += ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1));
  s1 += ((a == 2 && b == 1) || (a == 3 && b == 2) || (a == 1 && b == 3));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long k;
  int a, b, n = 3;
  cin >> k >> a >> b;
  vector<vector<int>> A(n + 1, vector<int>(n + 1)),
      B(n + 1, vector<int>(n + 1));
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> B[i][j];
    }
  }
  vector<pair<int, int>> vp;
  vp.push_back({a, b});
  int pos = -1;
  while (pos == -1) {
    auto p = vp.back();
    int x = p.first, y = p.second;
    pair<int, int> p2 = {A[x][y], B[x][y]};
    auto it = find(vp.begin(), vp.end(), p2);
    if (it != vp.end()) {
      pos = it - vp.begin();
    } else
      vp.push_back(p2);
  }
  long long s1 = 0, s2 = 0;
  for (int i = 0; i < pos && k; i++, k--) {
    f(vp[i].first, vp[i].second, s1, s2);
  }
  if (k) {
    long long cyMult = k / (vp.size() - pos), rem = k % (vp.size() - pos);
    long long s1g = 0, s2g = 0;
    for (int i = pos; i < vp.size(); i++) {
      f(vp[i].first, vp[i].second, s1g, s2g);
    }
    s1 += s1g * cyMult;
    s2 += s2g * cyMult;
    for (int i = pos; i < pos + rem; i++) {
      f(vp[i].first, vp[i].second, s1, s2);
    }
  }
  cout << s1 << ' ' << s2;
  return 0;
}
