#include <bits/stdc++.h>
using namespace std;
int aa[4][4];
int bb[4][4];
long long vis[4][4];
long long ans[4][4][2];
long long ans_a = 0, ans_b = 0;
bool win(long long a, long long b) {
  if (a == 1 && b == 3) return true;
  if (a == 2 && b == 1) return true;
  if (a == 3 && b == 2) return true;
  return false;
}
long long kk;
void solve(long long x, long long y, long long xx, long long yy, long long k) {
  ans[x][y][0] = xx;
  ans[x][y][1] = yy;
  vis[x][y] = k;
  if (x != y) {
    if (win(x, y)) {
      xx++;
    } else if (win(y, x)) {
      yy++;
    }
  }
  long long nx = aa[x][y];
  long long ny = bb[x][y];
  ans_a = xx;
  ans_b = yy;
  k--;
  if (k == 0)
    return;
  else if (vis[nx][ny]) {
    long long clen = vis[nx][ny] - k;
    long long gap_x = xx - ans[nx][ny][0];
    long long gap_y = yy - ans[nx][ny][1];
    xx += (k / clen) * gap_x;
    yy += (k / clen) * gap_y;
    k = k % clen;
    ans_a = xx;
    ans_b = yy;
    if (k == 0)
      return;
    else {
      memset(vis, 0, sizeof(vis));
      solve(nx, ny, xx, yy, k);
    }
  } else {
    solve(nx, ny, xx, yy, k);
  }
}
int main() {
  long long k, a, b;
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> aa[i][j];
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> bb[i][j];
    }
  }
  solve(a, b, 0, 0, k);
  cout << ans_a << " " << ans_b << "\n";
  return 0;
}
