#include <bits/stdc++.h>
using namespace std;
bool chk(pair<long long, long long> x) {
  if ((x.first == 3 && x.second == 2) || (x.first == 2 && x.second == 1) ||
      (x.first == 1 && x.second == 3))
    return true;
  else
    return false;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long k, a, b;
  cin >> k >> a >> b;
  multiset<pair<long long, long long> > con;
  vector<pair<long long, long long> > v[2];
  con.insert({a, b});
  v[0].push_back({a, b});
  long long alc[4][4], bob[4][4];
  for (long long i = (long long)(1); i <= (long long)(3); i++)
    for (long long j = (long long)(1); j <= (long long)(3); j++)
      cin >> alc[i][j];
  for (long long i = (long long)(1); i <= (long long)(3); i++)
    for (long long j = (long long)(1); j <= (long long)(3); j++)
      cin >> bob[i][j];
  long long f = 0;
  long long cnt = 0;
  while (1) {
    long long tmp;
    tmp = alc[a][b];
    b = bob[a][b];
    a = tmp;
    if (con.count({a, b}) == 1) f = 1;
    if (con.count({a, b}) == 2) break;
    v[f].push_back({a, b});
    con.insert({a, b});
  }
  long long pa = 0, push_back = 0;
  for (auto it : v[0]) {
    if (k == 0) break;
    k--;
    if (it.first == it.second) continue;
    if (chk(it))
      pa++;
    else
      push_back++;
  }
  long long c1 = 0, c2 = 0;
  for (auto it : v[1]) {
    if (it.first == it.second) continue;
    if (chk(it))
      c1++;
    else
      c2++;
  }
  long long tim = k / v[1].size();
  pa += c1 * tim;
  push_back += c2 * tim;
  k %= v[1].size();
  for (auto it : v[1]) {
    if (k == 0) break;
    k--;
    if (it.first == it.second) continue;
    if (chk(it))
      pa++;
    else
      push_back++;
  }
  cout << pa << " " << push_back;
}
