#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> re(long long a, long long b) {
  if (a == b)
    return make_pair(0, 0);
  else if (a == 2 && b == 1)
    return make_pair(1, 0);
  else if (a == 1 && b == 0)
    return make_pair(1, 0);
  else if (a == 0 && b == 2)
    return make_pair(1, 0);
  else
    return make_pair(0, 1);
}
int main() {
  long long k;
  cin >> k;
  long long ia, ib;
  cin >> ia >> ib;
  ia--, ib--;
  long long a[3][3], b[3][3];
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < 3; j++) {
      long long v;
      cin >> v;
      a[i][j] = v - 1;
      ;
    }
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < 3; j++) {
      long long v;
      cin >> v;
      b[i][j] = v - 1;
      ;
    }
  long long ra = 0, rb = 0;
  vector<pair<long long, long long> > v;
  vector<pair<long long, long long> > rep;
  auto val = re(ia, ib);
  ra += val.first, rb += val.second;
  v.push_back(make_pair(val.first, val.second));
  rep.push_back(make_pair(ia, ib));
  set<pair<long long, long long> > st;
  st.insert(make_pair(ia, ib));
  while (true) {
    long long va = a[ia][ib];
    long long vb = b[ia][ib];
    auto it = st.find(make_pair(va, vb));
    ia = va;
    ib = vb;
    if (it != st.end()) {
      break;
    } else {
      auto val = re(ia, ib);
      v.push_back(make_pair(val.first, val.second));
      rep.push_back(make_pair(ia, ib));
      ra += val.first, rb += val.second;
      st.insert(make_pair(va, vb));
    }
  }
  long long idx = -1;
  bool ok = false;
  long long ura = 0, urb = 0;
  long long ura2 = 0, urb2 = 0;
  vector<pair<long long, long long> > resto;
  for (long long i = 0; i < rep.size(); i++) {
    if (ok) {
      ura2 += v[i].first;
      urb2 += v[i].second;
      resto.push_back(make_pair(ura2, urb2));
    } else if (ia == rep[i].first && ib == rep[i].second) {
      ura2 += v[i].first;
      urb2 += v[i].second;
      resto.push_back(make_pair(ura2, urb2));
      idx = i;
      ok = true;
    } else {
      ura += v[i].first;
      urb += v[i].second;
    }
  }
  if (k < v.size()) {
    ra = 0, rb = 0;
    for (long long i = 0; i < k; i++) {
      ra += v[i].first;
      rb += v[i].second;
    }
    cout << ra << " " << rb << endl;
  } else if (k == v.size()) {
    cout << ra << " " << rb << endl;
  } else {
    ra = 0, rb = 0;
    k -= idx;
    ra += ura, rb += urb;
    long long rest = rep.size() - idx;
    if (rest != 0) {
      long long divi = k / rest;
      ra += divi * ura2;
      rb += divi * urb2;
      if (k % rest != 0) {
        ra += resto[(k % rest) - 1].first;
        rb += resto[(k % rest) - 1].second;
      }
    }
    cout << ra << " " << rb << endl;
  }
  return 0;
}
