#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long K = 2;
long long ch(long long a, long long b) {
  if (a == 1 && b == 2)
    return 0;
  else if (a == 2 && b == 3)
    return 0;
  else if (a == 3 && b == 1)
    return 0;
  else if (a == b)
    return 2;
  return 1;
}
bool mp[4000005] = {false};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long k, a, b;
  cin >> k >> a >> b;
  long long gr1[4][4], gr2[4][4];
  for (long long i = 1; i < 4; i++)
    for (long long j = 1; j < 4; j++) cin >> gr1[i][j];
  for (long long i = 1; i < 4; i++)
    for (long long j = 1; j < 4; j++) cin >> gr2[i][j];
  bool vis[4][4];
  memset(vis, false, sizeof(vis));
  long long c1 = 0, c2 = 0;
  vector<long long> v;
  vector<pair<long long, long long>> vv;
  while (k > 0 && !vis[a][b]) {
    vis[a][b] = true;
    if (ch(a, b) == 1) {
      v.push_back(1);
      vv.push_back({a, b});
    } else if (ch(a, b) == 0) {
      v.push_back(2);
      vv.push_back({a, b});
    } else {
      v.push_back(3);
      vv.push_back({a, b});
    }
    long long pr = a;
    a = gr1[pr][b];
    b = gr2[pr][b];
  }
  vector<long long> v1, v2;
  bool ch = true;
  for (long long i = 0; i < vv.size(); i++) {
    long long st = vv[i].first, en = vv[i].second;
    if (!(st == a && en == b) && ch) {
      v1.push_back(v[i]);
    } else {
      ch = false;
      v2.push_back(v[i]);
    }
  }
  long long an1 = 0;
  long long an2 = 0;
  for (long long i = 0; i < min((long long)v1.size(), k); i++) {
    if (v1[i] == 1)
      an1++;
    else if (v1[i] == 2)
      an2++;
  }
  k -= min((long long)v1.size(), k);
  for (long long i = 0; i < v2.size(); i++) {
    if (v2[i] == 1)
      c1++;
    else if (v2[i] == 2)
      c2++;
  }
  if (v2.size() == 0) {
    cout << an1 << " " << an2;
    return 0;
  }
  long long tm = k / v2.size();
  an1 += c1 * tm;
  an2 += c2 * tm;
  long long re = k % v2.size();
  for (long long i = 0; i < re; i++) {
    if (v2[i] == 1)
      an1++;
    else if (v2[i] == 2)
      an2++;
  }
  cout << an1 << " " << an2;
  return 0;
}
