#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
pair<int, int> adj[maxn][maxn];
bool visit[maxn][maxn], recstack[maxn][maxn];
long long k, a, b;
bool flag;
int cnt, cntC, cntA, cntB, cntCA, cntCB;
long long startx, starty, dp1A[maxn], dp1B[maxn], dpA[maxn], dpB[maxn];
int A[maxn][maxn], B[maxn][maxn];
void countInCycle(int a, int b) {
  if (startx == a && starty == b && flag) return;
  flag = true;
  cntC++;
  if (a == 1 && b == 3 || (a == 2 && b == 1) || (a == 3 && b == 2))
    cntCA++;
  else if ((b == 1 && a == 3) || (b == 2 && a == 1) || (b == 3 && a == 2))
    cntCB++;
  dpA[cntC] = cntCA;
  dpB[cntC] = cntCB;
  countInCycle(adj[a][b].first, adj[a][b].second);
}
void dfs(int a, int b) {
  visit[a][b] = true;
  recstack[a][b] = true;
  if ((a == 1 && b == 3) || (a == 2 && b == 1) || (a == 3 && b == 2))
    cntA++;
  else if ((b == 1 && a == 3) || (b == 2 && a == 1) || (b == 3 && a == 2))
    cntB++;
  cnt++;
  dp1A[cnt] = cntA;
  dp1B[cnt] = cntB;
  int x = adj[a][b].first;
  int y = adj[a][b].second;
  if (recstack[x][y]) {
    startx = x;
    starty = y;
    countInCycle(x, y);
  } else
    dfs(x, y);
  recstack[a][b] = false;
}
int main() {
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) cin >> A[i][j];
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) cin >> B[i][j];
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) adj[i][j] = make_pair(A[i][j], B[i][j]);
  }
  dfs(a, b);
  int lengthBeforeCycle = cnt - cntC;
  if (k <= lengthBeforeCycle)
    cout << dp1A[k] << " " << dp1B[k] << endl;
  else {
    k = k - lengthBeforeCycle;
    long long temp = k / cntC;
    long long temp1 = k % cntC;
    cout << dp1A[lengthBeforeCycle] + temp * dpA[cntC] + dpA[temp1] << " "
         << dp1B[lengthBeforeCycle] + temp * dpB[cntC] + dpB[temp1] << endl;
  }
  return 0;
}
