#include <bits/stdc++.h>
using namespace std;
int vis[5][5];
int ac[5][5], bc[5][5];
pair<int, int> sum[100];
pair<int, int> cal(int a, int b) {
  if (a == 1) {
    if (b == 1)
      return pair<int, int>(0, 0);
    else if (b == 2)
      return pair<int, int>(0, 1);
    return pair<int, int>(1, 0);
  } else if (a == 2) {
    if (b == 1)
      return pair<int, int>(1, 0);
    else if (b == 2)
      return pair<int, int>(0, 0);
    return pair<int, int>(0, 1);
  } else {
    if (b == 1)
      return pair<int, int>(0, 1);
    else if (b == 2)
      return pair<int, int>(1, 0);
    return pair<int, int>(0, 0);
  }
}
int main() {
  long long k, pa = 0, pb = 0;
  int a, b;
  scanf("%lld%d%d", &k, &a, &b);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &ac[i][j]);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= 3; j++) scanf("%d", &bc[i][j]);
  int sz = 1;
  vis[a][b] = sz++;
  sum[1] = cal(a, b);
  int last = 1;
  for (int i = 1; i <= k; i++) {
    int na = ac[a][b];
    int nb = bc[a][b];
    if (vis[na][nb]) {
      last = vis[na][nb];
      break;
    }
    a = na, b = nb;
    vis[a][b] = sz;
    sum[sz] = pair<int, int>(sum[sz - 1].first + cal(a, b).first,
                             sum[sz - 1].second + cal(a, b).second);
    sz++;
  }
  sz--;
  if (sz == k) {
    printf("%d %d\n", sum[sz].first, sum[sz].second);
    return 0;
  }
  pa += sum[last - 1].first;
  pb += sum[last - 1].second;
  k -= last - 1;
  long long dv = k / (sz - last + 1);
  pa += dv * (sum[sz].first - sum[last - 1].first);
  pb += dv * (sum[sz].second - sum[last - 1].second);
  k %= (sz - last + 1);
  if (k != 0) {
    pa += (sum[last + k - 1].first - sum[last - 1].first);
    pb += (sum[last + k - 1].second - sum[last - 1].second);
  }
  printf("%lld %lld\n", pa, pb);
}
