#include <bits/stdc++.h>
using namespace std;
long long k;
int A[2][3][3];
int current[2];
long long currentPoint[2];
int turn[3][3];
vector<int> points[2];
int calc(int me, int you) { return (me == ((you + 1) % 3)) ? 1 : 0; }
void exec() {
  cin >> k >> current[0] >> current[1];
  current[0]--;
  current[1]--;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        scanf("%d", &A[i][j][k]);
        A[i][j][k]--;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      turn[i][j] = -1;
    }
  }
  long long currentTurn = 1;
  bool isFirst = false;
  long long remainTurn = k;
  while (currentTurn <= k) {
    if (!isFirst && turn[current[0]][current[1]] != -1) {
      long long diffTurn = currentTurn - turn[current[0]][current[1]];
      long long loop = remainTurn / diffTurn;
      for (int i = 0; i < 2; i++) {
        long long diffPoint =
            currentPoint[i] - points[i][turn[current[0]][current[1]] - 1];
        currentPoint[i] += diffPoint * loop;
      }
      currentTurn += diffTurn * loop;
      remainTurn -= diffTurn * loop;
      isFirst = true;
      continue;
    }
    turn[current[0]][current[1]] = currentTurn;
    int prev[2];
    for (int i = 0; i < 2; i++) {
      prev[i] = current[i];
    }
    for (int i = 0; i < 2; i++) {
      points[i].push_back(currentPoint[i]);
      current[i] = A[i][prev[0]][prev[1]];
      currentPoint[i] += calc(prev[i], prev[1 - i]);
    }
    currentTurn++;
    remainTurn--;
  }
  printf("%lld %lld\n", currentPoint[0], currentPoint[1]);
}
void solve() {
  int t = 1;
  for (int i = 0; i < t; i++) {
    exec();
  }
}
int main() {
  solve();
  return 0;
}
