#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T>
using que = queue<T>;
template <typename T>
using deq = deque<T>;
template <typename T>
T id(T b) {
  return b;
};
template <typename T>
void chmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename S, typename K>
bool contains(S &s, K k) {
  return s.find(k) != s.end();
}
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
constexpr ll TEN(int n) {
  if (n == 0)
    return 1LL;
  else
    return 10LL * TEN(n - 1);
}
ll k;
int a, b;
int alice[3][3];
int bob[3][3];
ll battle(int a, int b) {
  if (a == b) {
    return 0;
  } else if ((a == 2 && b == 1) || (a == 1 && b == 0) || (a == 0 && b == 2)) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  fastio();
  cin >> k >> a >> b;
  a--, b--;
  for (int i = 0; i < int(3); i++)
    for (int j = 0; j < int(3); j++) {
      cin >> alice[i][j];
      alice[i][j]--;
    }
  for (int i = 0; i < int(3); i++)
    for (int j = 0; j < int(3); j++) {
      cin >> bob[i][j];
      bob[i][j]--;
    }
  ll sa = battle(a, b), sb = battle(b, a);
  map<pii, int> hand;
  map<pii, pll> score;
  hand[make_pair(a, b)] = 0;
  score[make_pair(a, b)] = make_pair(sa, sb);
  k--;
  int t = 1;
  bool done = false;
  while (k > 0) {
    int newa = alice[a][b];
    int newb = bob[a][b];
    a = newa, b = newb;
    sa += battle(a, b);
    sb += battle(b, a);
    k--;
    if (!done && contains(hand, make_pair(a, b))) {
      ll d = t - hand[make_pair(a, b)];
      auto [ta, tb] = score[make_pair(a, b)];
      ll da = sa - ta;
      ll db = sb - tb;
      ll p = k / d;
      sa += p * da;
      sb += p * db;
      k %= d;
      done = true;
    }
    if (!done) {
      hand[make_pair(a, b)] = t;
      score[make_pair(a, b)] = make_pair(sa, sb);
      t++;
    }
  }
  cout << sa << " " << sb << endl;
  return 0;
}
