#include <bits/stdc++.h>
using namespace std;
int p[4][4], q[4][4];
int c[1000100][3];
int vis[4][4];
long long k;
int l, r;
int a, b, tot;
long long step;
void dfs(int x, int y) {
  tot++;
  c[tot][0] = c[tot - 1][0];
  c[tot][1] = c[tot - 1][1];
  if ((x == 3 && y == 2) || (x == 2 && y == 1) || (x == 1 && y == 3))
    c[tot][0]++;
  else if (x != y)
    c[tot][1]++;
  if (vis[x][y] != 0 && tot != 1) {
    tot--;
    l = vis[x][y];
    r = tot;
    return;
  }
  if (tot >= k) return;
  vis[x][y] = tot;
  dfs(p[x][y], q[x][y]);
}
int main() {
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> p[i][j];
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> q[i][j];
    }
  }
  dfs(a, b);
  long long ansa = 0, ansb = 0;
  if (tot >= k) {
    cout << c[k][0] << ' ' << c[k][1];
    return 0;
  }
  ansa = (k - l + 1) / (long long)(r - l + 1) *
             (long long)(c[r][0] - c[l - 1][0]) +
         (long long)(c[l - 1 + ((k - r) % (r - l + 1))][0]);
  ansb = (k - l + 1) / (long long)(r - l + 1) *
             (long long)(c[r][1] - c[l - 1][1]) +
         (long long)(c[l - 1 + ((k - r) % (r - l + 1))][1]);
  cout << ansa << ' ' << ansb;
  return 0;
}
