#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> alice;
vector<vector<int>> bob;
vector<vector<int>> used(3, vector<int>(3, 0));
int startA, startB;
long long k, scoreA, scoreB;
void input() {
  cin >> k;
  cin >> startA;
  cin >> startB;
  startA--;
  startB--;
  int num;
  for (int i = 0; i < 3; i++) {
    vector<int> temp;
    for (int j = 0; j < 3; j++) {
      cin >> num;
      num--;
      temp.push_back(num);
    }
    alice.push_back(temp);
  }
  for (int i = 0; i < 3; i++) {
    vector<int> temp;
    for (int j = 0; j < 3; j++) {
      cin >> num;
      num--;
      temp.push_back(num);
    }
    bob.push_back(temp);
  }
}
void compare(int a, int b) {}
void output() { cout << scoreA << " " << scoreB << endl; }
void process() {
  vector<pair<int, int>> cycle;
  long long cnt = k;
  while (cnt > 0) {
    int i = startA;
    int j = startB;
    if (used[i][j] == 1) {
      cycle.push_back(make_pair(i, j));
    }
    if (used[i][j] == 2) break;
    used[i][j] += 1;
    if (startA == 0 && startB == 2 || startA == 1 && startB == 0 ||
        startA == 2 && startB == 1)
      scoreA++;
    if (startA == 2 && startB == 0 || startA == 0 && startB == 1 ||
        startA == 1 && startB == 2)
      scoreB++;
    startA = alice[i][j];
    startB = bob[i][j];
    cnt--;
  }
  if (cycle.size() != 0) {
    int cycle_scoreA = 0;
    int cycle_scoreB = 0;
    for (int i = 0; i < cycle.size(); i++) {
      if (cycle[i].first == 0 && cycle[i].second == 2 ||
          cycle[i].first == 1 && cycle[i].second == 0 ||
          cycle[i].first == 2 && cycle[i].second == 1)
        cycle_scoreA++;
      if (cycle[i].first == 2 && cycle[i].second == 0 ||
          cycle[i].first == 0 && cycle[i].second == 1 ||
          cycle[i].first == 1 && cycle[i].second == 2)
        cycle_scoreB++;
    }
    long long div_cnt = cnt / cycle.size();
    int mod_cnt = cnt % cycle.size();
    scoreA += cycle_scoreA * div_cnt;
    scoreB += cycle_scoreB * div_cnt;
    for (int i = 0; i < mod_cnt; i++) {
      if (cycle[i].first == 0 && cycle[i].second == 2 ||
          cycle[i].first == 1 && cycle[i].second == 0 ||
          cycle[i].first == 2 && cycle[i].second == 1)
        scoreA++;
      if (cycle[i].first == 2 && cycle[i].second == 0 ||
          cycle[i].first == 0 && cycle[i].second == 1 ||
          cycle[i].first == 1 && cycle[i].second == 2)
        scoreB++;
    }
  }
}
int main() {
  input();
  process();
  output();
  return 0;
}
