#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 100005;
map<pair<int, int>, int> mp;
long long t1[10000007];
long long t2[10000007];
int ah[5][5], bh[5][5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long k, a, b;
  cin >> k >> a >> b;
  for (long long i = (1); i < (4); i++) {
    for (long long j = (1); j < (4); j++) {
      cin >> ah[i][j];
    }
  }
  for (long long i = (1); i < (4); i++) {
    for (long long j = (1); j < (4); j++) {
      cin >> bh[i][j];
    }
  }
  long long p = k;
  int o = 0;
  int osh = 0;
  while (true) {
    o++;
    if (mp[make_pair(a, b)] != 0) {
      osh = mp[make_pair(a, b)];
      break;
    }
    if (a > b and !(a == 3 and b == 1)) {
      t1[o] = t1[o - 1] + 1;
      t2[o] = t2[o - 1];
    } else if (a == 1 and b == 3) {
      t1[o] = t1[o - 1] + 1;
      t2[o] = t2[o - 1];
    } else if (b > a and !(b == 3 and a == 1)) {
      t2[o] = t2[o - 1] + 1;
      t1[o] = t1[o - 1];
    } else if (b == 1 and a == 3) {
      t2[o] = t2[o - 1] + 1;
      t1[o] = t1[o - 1];
    } else {
      t1[o] = t1[o - 1];
      t2[o] = t2[o - 1];
    }
    mp[make_pair(a, b)] = o;
    int l = a;
    a = ah[a][b];
    b = bh[l][b];
    p--;
    if (p == 0) {
      break;
    }
  }
  if (p == 0) {
    cout << t1[k] << " " << t2[k];
    return 0;
  }
  long long averj = 0, bverj = 0;
  o--;
  averj = t1[osh - 1];
  bverj = t2[osh - 1];
  k -= (osh - 1);
  averj += k / (o - osh + 1) * (t1[o] - t1[osh - 1]) +
           t1[osh - 1 + (k % (o - osh + 1))] - t1[osh - 1];
  bverj += k / (o - osh + 1) * (t2[o] - t2[osh - 1]) +
           t2[osh - 1 + (k % (o - osh + 1))] - t2[osh - 1];
  cout << averj << " " << bverj;
  return 0;
}
