#include <bits/stdc++.h>
int depth[4][4];
std::pair<int, int> gain[10];
std::pair<int, int> move[4][4];
bool win(int mine, int oppo) {
  if (mine == 1 && oppo == 3) {
    return true;
  }
  if (mine == 2 && oppo == 1) {
    return true;
  }
  if (mine == 3 && oppo == 2) {
    return true;
  }
  return false;
}
int main(void) {
  long long k;
  int a, b;
  scanf("%I64d%d%d", &k, &a, &b);
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      scanf("%d", &move[i][j].first);
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      scanf("%d", &move[i][j].second);
    }
  }
  std::pair<int, int> pos = std::make_pair(a, b);
  int len = 0;
  while (true) {
    if (depth[pos.first][pos.second]) {
      break;
    }
    depth[pos.first][pos.second] = ++len;
    pos = move[pos.first][pos.second];
  }
  int loop = len - depth[pos.first][pos.second] + 1;
  std::pair<int, int> loop_start = pos;
  for (int k = 1; k <= loop; k++) {
    gain[k].first = (win(pos.first, pos.second) ? 1 : 0) + gain[k - 1].first;
    gain[k].second = (win(pos.second, pos.first) ? 1 : 0) + gain[k - 1].second;
    pos = move[pos.first][pos.second];
  }
  long long res1 = 0, res2 = 0;
  pos = std::make_pair(a, b);
  while (true) {
    if (pos.first == loop_start.first && pos.second == loop_start.second) {
      break;
    }
    if (win(pos.first, pos.second)) {
      res1++;
    } else if (win(pos.second, pos.first)) {
      res2++;
    }
    k--;
    if (k == 0) {
      break;
    }
    pos = move[pos.first][pos.second];
  }
  if (k != 0) {
    long long whole = k / loop;
    long long remain = k % loop;
    res1 += gain[loop].first * whole + gain[remain].first;
    res2 += gain[loop].second * whole + gain[remain].second;
  }
  printf("%I64d %I64d", res1, res2);
  return 0;
}
