#include <bits/stdc++.h>   using namespace std;   long long score(long long a, long long b) {     if (a == b)       return 0;     else if ((a == 3 && b == 2) || (a == 2 && b == 1) || (a == 1 && b == 3))       return 1;     else       return 0;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long k, a, b, ca, cb, ncl, cl, csa, csb, pa, pb;     long long d[4][4][4] = {};     long long ch[4][4][4];     long long sc[100][2] = {};     cin >> k >> a >> b;     for (long long k = 1; k <= 2; k++)       for (long long i = 1; i <= 3; i++)         for (long long j = 1; j <= 3; j++) cin >> ch[i][j][k];     d[a][b][0] = 1;     d[a][b][1] = score(a, b);     d[a][b][2] = score(b, a);     sc[1][0] = score(a, b);     sc[1][1] = score(b, a);     ca = a;     cb = b;     while (true) {       long long na, nb;       na = ch[ca][cb][1];       nb = ch[ca][cb][2];       if (d[na][nb][0] == 0) {         d[na][nb][0] = d[ca][cb][0] + 1;         d[na][nb][1] = d[ca][cb][1] + score(na, nb);         d[na][nb][2] = d[ca][cb][2] + score(nb, na);         sc[d[na][nb][0]][0] = d[na][nb][1];         sc[d[na][nb][0]][1] = d[na][nb][2];         ca = na;         cb = nb;       } else {         ncl = d[na][nb][0] - 1;         cl = d[ca][cb][0] - d[na][nb][0] + 1;         csa = d[ca][cb][1] - d[na][nb][1] + score(na, nb);         csb = d[ca][cb][2] - d[na][nb][2] + score(nb, na);         break;       }     }     if (k <= ncl) {       pa = sc[k][0];       pb = sc[k][1];     } else {       long long km = (k - ncl) % cl;       pa = sc[ncl + km][0] + ((k - ncl) / cl) * csa;       pb = sc[ncl + km][1] + ((k - ncl) / cl) * csb;     }     cout << pa <<     << pb << endl;     return 0;   }   