#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
int v1[maxn][maxn];
int v2[maxn][maxn];
long long vis[maxn][maxn];
vector<pair<long long, long long> > v;
pair<long long, long long> calc(int l, int r) {
  long long num = 0;
  int ans1 = 0, ans2 = 0;
  for (int i = l; i < r; i++) {
    int x = v[i].first;
    int y = v[i].second;
    if (x == y) continue;
    if ((x == 3 && y == 2) || (x == 2 && y == 1) || (x == 1 && y == 3))
      ans1++;
    else
      ans2++;
  }
  return pair<long long, long long>(ans1, ans2);
}
int main() {
  long long k;
  int a, b;
  while (cin >> k >> a >> b) {
    v.clear();
    int flag = 0;
    memset(vis, -1, sizeof(vis));
    for (int i = 1; i <= 3; i++)
      for (int j = 1; j <= 3; j++) cin >> v1[i][j];
    for (int i = 1; i <= 3; i++)
      for (int j = 1; j <= 3; j++) cin >> v2[i][j];
    long long ans1 = 0, ans2 = 0;
    long long id = 1e18 + 10;
    int x, y;
    pair<long long, long long> p;
    for (long long i = 0; i < k; i++) {
      int z = a;
      x = a;
      y = b;
      v.push_back(pair<long long, long long>(x, y));
      if (vis[x][y] == -1)
        vis[x][y] = i;
      else {
        pair<long long, long long> p3 = calc(0, vis[x][y]);
        p = calc(vis[x][y], i);
        long long cha = i - vis[x][y];
        long long mod = (k - vis[x][y]) % cha;
        long long r = k - vis[x][y] - mod;
        p.first *= r / (cha);
        p.second *= r / (cha);
        pair<long long, long long> p2 = calc(vis[x][y], vis[x][y] + mod);
        p.first += p2.first;
        p.second += p2.second;
        p.first += p3.first;
        p.second += p3.second;
        flag = 1;
        break;
      }
      a = v1[a][b];
      b = v2[z][b];
    }
    if (!flag) p = calc(0, k);
    ans1 = p.first;
    ans2 = p.second;
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
