#include <bits/stdc++.h>
using namespace std;
long long arr[2][4][4];
deque<pair<long long, long long> > match;
map<pair<long long, long long>, long long> finded;
int main() {
  long long k, a, b;
  cin >> k >> a >> b;
  for (long long i = 0; i < 2; i++) {
    for (long long j = 1; j < 4; j++) {
      for (long long k1 = 1; k1 < 4; k1++) {
        cin >> arr[i][j][k1];
      }
    }
  }
  match.push_back({a, b});
  finded[{a, b}] = true;
  do {
    long long na = a, nb = b;
    na = arr[0][a][b];
    nb = arr[1][a][b];
    a = na;
    b = nb;
    match.push_back({a, b});
    if (finded[{a, b}]) break;
    finded[{a, b}] = true;
  } while (1);
  long long wp0 = 0, wp1 = 0, a0 = 0, a1 = 0;
  {
    while (match[0] != match[match.size() - 1]) {
      k--;
      if (match[0].first == 2 && match[0].second == 1)
        a0++;
      else if (match[0].first == 3 && match[0].second == 2)
        a0++;
      else if (match[0].first == 1 && match[0].second == 3)
        a0++;
      if (match[0].first == 2 && match[0].second == 3)
        a1++;
      else if (match[0].first == 3 && match[0].second == 1)
        a1++;
      else if (match[0].first == 1 && match[0].second == 2)
        a1++;
      match.pop_front();
      if (k <= 0) {
        cout << a0 << ' ' << a1 << endl;
        return 0;
      }
    }
    k--;
    if (match[0].first == 2 && match[0].second == 1)
      a0++;
    else if (match[0].first == 3 && match[0].second == 2)
      a0++;
    else if (match[0].first == 1 && match[0].second == 3)
      a0++;
    if (match[0].first == 2 && match[0].second == 3)
      a1++;
    else if (match[0].first == 3 && match[0].second == 1)
      a1++;
    else if (match[0].first == 1 && match[0].second == 2)
      a1++;
    match.pop_front();
    if (k <= 0) {
      cout << a0 << ' ' << a1 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < match.size(); i++) {
    if (match[i].first == 2 && match[i].second == 1)
      wp0++;
    else if (match[i].first == 3 && match[i].second == 2)
      wp0++;
    else if (match[i].first == 1 && match[i].second == 3)
      wp0++;
    if (match[i].first == 2 && match[i].second == 3)
      wp1++;
    else if (match[i].first == 3 && match[i].second == 1)
      wp1++;
    else if (match[i].first == 1 && match[i].second == 2)
      wp1++;
  }
  a0 += wp0 * (k / match.size());
  a1 += wp1 * (k / match.size());
  k %= match.size();
  for (long long i = 0; i < k; i++) {
    if (match[i].first == 2 && match[i].second == 1)
      a0++;
    else if (match[i].first == 3 && match[i].second == 2)
      a0++;
    else if (match[i].first == 1 && match[i].second == 3)
      a0++;
    if (match[i].first == 2 && match[i].second == 3)
      a1++;
    else if (match[i].first == 3 && match[i].second == 1)
      a1++;
    else if (match[i].first == 1 && match[i].second == 2)
      a1++;
  }
  cout << a0 << ' ' << a1 << endl;
  return 0;
}
