#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
const ll mod7 = 1000000007, mod1 = 1000000000, OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi = acos(-1);
const ld rad = Pi / 180.0;
long long power(long long a, long long b, ll mod) {
  if (!b) return 1ll;
  if (b == 1) return a % mod;
  long long r = power(a, b / 2ll, mod) % mod;
  if (b % 2ll)
    return ((r * (a % mod) % mod) * r) % mod;
  else
    return (r * r) % mod;
}
ll nCr(ll n, ll m) { return (m == 0) ? 1 : n * nCr(n - 1, m - 1) / m; }
bool checkDivisibility(ll n, int digit) {
  return (digit == 0 || (digit != 0 && n % digit == 0));
}
bool allDigitsDivide(ll n) {
  ll temp = n;
  while (temp > 0) {
    ll digit = temp % 10;
    if (!(checkDivisibility(n, digit))) return false;
    temp /= 10;
  }
  return true;
}
bool comp(pair<int, char> a, pair<int, char> b) { return a.first > b.first; }
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int winner(int a, int b) {
  if ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1)) return 0;
  if ((a == 2 && b == 1) || (a == 1 && b == 3) || (a == 3 && b == 2)) return 1;
  if (a == b) return 2;
}
int alice[3][3];
int bob[3][3];
bool visited[4][4];
ll ctr = 0, x = 0, y = 0;
int n, m;
ll k;
void dfs(int a, int b) {
  if (!visited[a][b] && ctr < k) {
    if (winner(a, b) == 1)
      x++;
    else if (winner(a, b) == 0)
      y++;
    ctr++;
    visited[a][b] = 1;
    dfs(alice[a - 1][b - 1], bob[a - 1][b - 1]);
  } else {
    m = a;
    n = b;
  }
}
int main() {
  int a, b;
  cin >> k >> a >> b;
  memset(visited, 0, sizeof(visited));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) cin >> alice[i][j];
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) cin >> bob[i][j];
  }
  dfs(a, b);
  if (ctr < k) {
    ll cycle = 0, c = m, d = n, x1 = 0, y1 = 0;
    while (true) {
      if (winner(c, d) == 1)
        x1++;
      else if (winner(c, d) == 0)
        y1++;
      int temp1 = c, temp2 = d;
      c = alice[temp1 - 1][temp2 - 1];
      d = bob[temp1 - 1][temp2 - 1];
      cycle++;
      if (c == m && d == n) break;
    }
    ll z = k - ctr;
    x += (x1 * (z / cycle));
    y += (y1 * (z / cycle));
    for (int i = 0; i < z % cycle; i++) {
      if (winner(m, n) == 1)
        x++;
      else if (winner(m, n) == 0)
        y++;
      int temp1 = m, temp2 = n;
      m = alice[temp1 - 1][temp2 - 1];
      n = bob[temp1 - 1][temp2 - 1];
    }
  }
  cout << x << " " << y;
}
