#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000001;
int A[4][4];
int B[4][4];
long long int vis[4][4];
long long int vis2[4][4];
long long int vis3[4][4];
int Win(int a, int b) {
  if (a == 3 && b == 2) return 1;
  if (a == 2 && b == 1) return 1;
  if (a == 1 && b == 3) return 1;
  if (a == 2 && b == 3) return 2;
  if (a == 1 && b == 2) return 2;
  if (a == 3 && b == 1) return 2;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int k;
  int a, b;
  cin >> k >> a >> b;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) cin >> A[i + 1][j + 1];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) cin >> B[i + 1][j + 1];
  long long int cont = 1;
  long long int uno = 0, dos = 0;
  while (k > 0) {
    if (vis[a][b]) {
      long long int more = k / (cont - vis[a][b]);
      long long int one = uno - vis2[a][b];
      long long int two = dos - vis3[a][b];
      uno += more * one;
      dos += more * two;
      k -= more * (cont - vis[a][b]);
      break;
    }
    vis[a][b] = cont++;
    vis2[a][b] = uno;
    vis3[a][b] = dos;
    int result = Win(a, b);
    if (result == 1)
      uno++;
    else if (result == 2)
      dos++;
    int aux = a;
    a = A[a][b];
    b = B[aux][b];
    k--;
  }
  while (k > 0) {
    int result = Win(a, b);
    if (result == 1)
      uno++;
    else if (result == 2)
      dos++;
    int aux = a;
    a = A[a][b];
    b = B[aux][b];
    k--;
  }
  cout << uno << " " << dos << '\n';
  return 0;
}
