#include <bits/stdc++.h>
using namespace std;
long long a, b, k, i, j, pa[5][5], pb[5][5], a1, b1;
long long ans1, ans2, d[5][5], t, diff1, diff2;
pair<long long, long long> res[5][5];
int main() {
  cin >> k >> a >> b;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) cin >> pa[i][j];
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) cin >> pb[i][j];
  }
  while (!d[a][b] && k) {
    if ((a == 1 && b == 3) || (a == 2 && b == 1) || (a == 3 && b == 2)) ans1++;
    if ((b == 1 && a == 3) || (b == 2 && a == 1) || (b == 3 && a == 2)) ans2++;
    res[a][b] = make_pair(ans1, ans2);
    d[a][b] = t++;
    a1 = a;
    b1 = b;
    a = pa[a1 - 1][b1 - 1];
    b = pb[a1 - 1][b1 - 1];
    k--;
  };
  if (k == 0) {
    cout << ans1 << " " << ans2;
    return 0;
  }
  diff1 = res[a1][b1].first - res[a][b].first;
  diff2 = res[a1][b1].second - res[a][b].second;
  if ((a == 1 && b == 3) || (a == 2 && b == 1) || (a == 3 && b == 2)) diff1++;
  if ((b == 1 && a == 3) || (b == 2 && a == 1) || (b == 3 && a == 2)) diff2++;
  ans1 += (k / (d[a1][b1] - d[a][b] + 1)) * diff1;
  ans2 += (k / (d[a1][b1] - d[a][b] + 1)) * diff2;
  k %= (d[a1][b1] - d[a][b] + 1);
  while (k) {
    if ((a == 1 && b == 3) || (a == 2 && b == 1) || (a == 3 && b == 2)) ans1++;
    if ((b == 1 && a == 3) || (b == 2 && a == 1) || (b == 3 && a == 2)) ans2++;
    a1 = a;
    b1 = b;
    a = pa[a1 - 1][b1 - 1];
    b = pb[a1 - 1][b1 - 1];
    k--;
  }
  cout << ans1 << " " << ans2;
}
