#include <bits/stdc++.h>
using namespace std;
using namespace std;
unsigned int ax[3][3], bx[3][3];
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  unsigned long long k;
  unsigned int a, b;
  cin >> k >> a >> b;
  for (unsigned int i = 0; i < 3; ++i)
    for (unsigned int j = 0; j < 3; ++j) cin >> ax[i][j];
  for (unsigned int i = 0; i < 3; ++i)
    for (unsigned int j = 0; j < 3; ++j) cin >> bx[i][j];
  map<pair<unsigned int, unsigned int>, unsigned int> v;
  vector<pair<unsigned int, unsigned int>> q;
  q.push_back(make_pair(a, b));
  v[make_pair(a, b)] = 0;
  unsigned int d = 0;
  pair<unsigned int, unsigned int> p(a, b);
  for (unsigned int i = 1; i < k; ++i) {
    unsigned int aa = ax[a - 1][b - 1], bb = bx[a - 1][b - 1];
    a = aa, b = bb;
    p = make_pair(a, b);
    map<pair<unsigned int, unsigned int>, unsigned int>::iterator it =
        v.lower_bound(p);
    if (it == v.end() || it->first != p) {
      it = v.insert(it, make_pair(p, i));
      q.push_back(p);
    } else {
      d = i;
      break;
    }
  }
  unsigned long long ca = 0, cb = 0;
  unsigned int z = q.size();
  unsigned int ra[3][3] = {{0, 0, 1}, {1, 0, 0}, {0, 1, 0}};
  {
    unsigned int h = 0;
    for (; h < z && q[h] != p; ++h) {
      ca += ra[q[h].first - 1][q[h].second - 1];
      cb += ra[q[h].second - 1][q[h].first - 1];
    }
    k -= h;
    unsigned long long cl = 0, cca = 0, ccb = 0;
    unsigned int ch = h;
    for (; ch < z; ++ch) {
      cca += ra[q[ch].first - 1][q[ch].second - 1];
      ccb += ra[q[ch].second - 1][q[ch].first - 1];
      ++cl;
    }
    ca += k / cl * cca;
    cb += k / cl * ccb;
    k %= cl;
    cl = 0;
    for (; cl < k; ++cl) {
      ca += ra[q[h].first - 1][q[h].second - 1];
      cb += ra[q[h].second - 1][q[h].first - 1];
      ++h;
    }
  }
  cout << ca << ' ' << cb << endl;
  return 0;
}
