#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
using namespace std;
long long link1[5][5];
long long link2[5][5];
long long k1 = 0, k2 = 0;
long long used[5][5];
void check(long long x, long long y) {
  if (x == 1) {
    if (y == 2) ++k2;
    if (y == 3) ++k1;
  }
  if (x == 2) {
    if (y == 1) ++k1;
    if (y == 3) ++k2;
  }
  if (x == 3) {
    if (y == 2) ++k1;
    if (y == 1) ++k2;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long k, a, b, i, j, cnt = 0, aa, bb;
  cin >> k >> a >> b;
  aa = a, bb = b;
  for (i = 1; i <= 3; ++i)
    for (j = 1; j <= 3; ++j) cin >> link1[i][j];
  for (i = 1; i <= 3; ++i)
    for (j = 1; j <= 3; ++j) cin >> link2[i][j];
  if (k <= 1000) {
    for (i = 1; i <= k; ++i) {
      check(a, b);
      long long xx = b, yy = a;
      a = link1[yy][xx];
      b = link2[yy][xx];
    }
    cout << k1 << " " << k2 << endl;
    return 0;
  }
  while (1) {
    if (used[a][b]) {
      long long x = aa, y = bb;
      while (1) {
        if (x == a && y == b) break;
        check(x, y);
        long long xx = x, yy = y;
        x = link1[xx][yy];
        y = link2[xx][yy];
        k--;
      }
      long long ans1 = k1, ans2 = k2;
      k1 = 0, k2 = 0;
      while (1) {
        ++cnt;
        check(x, y);
        long long xx = x, yy = y;
        x = link1[xx][yy];
        y = link2[xx][yy];
        if (x == a && y == b) break;
      }
      long long kol = k / cnt;
      k1 *= kol, k2 *= kol;
      k %= cnt;
      for (i = 1; i <= k; ++i) {
        check(a, b);
        long long xx = b, yy = a;
        a = link1[yy][xx];
        b = link2[yy][xx];
      }
      cout << ans1 + k1 << " " << ans2 + k2 << endl;
      return 0;
    }
    used[a][b] = 1;
    long long xx = b, yy = a;
    a = link1[yy][xx];
    b = link2[yy][xx];
  }
  return 0;
}
