#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> get(long long a, long long b) {
  if (a == b)
    return {0, 0};
  else if (a == 3 && b == 2)
    return {1, 0};
  else if (a == 2 && b == 3)
    return {0, 1};
  else if (a == 2 && b == 1)
    return {1, 0};
  else if (a == 1 && b == 2)
    return {0, 1};
  else if (a == 1 && b == 3)
    return {1, 0};
  else
    return {0, 1};
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long k, a, b;
  cin >> k >> a >> b;
  long long alice[4][4], bob[4][4];
  for (long long i = 1; i <= 3; i++)
    for (long long j = 1; j <= 3; j++) cin >> alice[i][j];
  for (long long i = 1; i <= 3; i++)
    for (long long j = 1; j <= 3; j++) cin >> bob[i][j];
  long long aa = 0, bb = 0;
  map<pair<long long, long long>, long long> mp;
  map<pair<long long, long long>, pair<long long, long long> > pt;
  long long cnt = 1;
  long long f = true;
  while (k > 0) {
    auto x = get(a, b);
    aa += x.first;
    bb += x.second;
    mp[{a, b}] = cnt++;
    pt[{a, b}] = {aa, bb};
    k--;
    long long na = alice[a][b];
    long long nb = bob[a][b];
    a = na, b = nb;
    if (f && mp.find({a, b}) != mp.end()) {
      long long cycle = cnt - mp[{a, b}];
      long long tt = k / cycle;
      k %= cycle;
      auto x = get(a, b);
      aa += tt * (aa - pt[{a, b}].first + x.first);
      bb += tt * (bb - pt[{a, b}].second + x.second);
      f = false;
    }
  }
  cout << aa << " " << bb << endl;
}
