#include <bits/stdc++.h>
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  itval(++it, args...);
}
const long long int MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {
  cout << x << "\n";
}
template <typename T>
inline void printvec(T x) {
  for (auto a : x) cout << a << ' ';
  cout << '\n';
}
struct custom {
  bool operator()(
      const pair<pair<long long int, long long int>, long long int> &p1,
      const pair<pair<long long int, long long int>, long long int> &p2) const {
    if (p1.first.first == p2.first.first) {
      return p1.first.second < p2.first.second;
    }
    return p1.first.first < p2.first.first;
  }
};
long long int get_pow(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
const long long int N = 5e3 + 5, inf = 1e18;
long long int at[3][3], bt[3][3];
map<pair<long long int, long long int>,
    std::vector<pair<long long int, long long int>>>
    mp;
map<pair<long long int, long long int>, pair<long long int, long long int>> par;
map<pair<long long int, long long int>, bool> vis;
long long int cyc = 0, f = 0;
std::vector<pair<long long int, long long int>> vals;
pair<long long int, long long int> start;
void dfs(pair<long long int, long long int> s,
         pair<long long int, long long int> p) {
  vis[s] = 1;
  par[s] = p;
  if (f) {
    return;
  }
  for (auto x : mp[s]) {
    if (vis[x]) {
      f = 1;
      auto t = s;
      while (t != x) {
        vals.push_back(t);
        cyc++;
        t = par[t];
      }
      vals.push_back(x);
      cyc++;
      return;
    }
    dfs(x, s);
  }
}
pair<long long int, long long int> score(long long int x, long long int y) {
  x++;
  y++;
  if (x == y) {
    return {0ll, 0ll};
  }
  if ((x == 3 && y == 2) || (x == 1 && y == 3) || (x == 2 && y == 1)) {
    return {1, 0};
  }
  return {0, 1};
}
void solve() {
  long long int k, a, b;
  cin >> k >> a >> b;
  a--;
  b--;
  for (long long int i = (long long int)0; i < (long long int)(3); i++)
    for (long long int j = (long long int)0; j < (long long int)(3); j++)
      cin >> at[i][j];
  for (long long int i = (long long int)0; i < (long long int)(3); i++)
    for (long long int j = (long long int)0; j < (long long int)(3); j++)
      cin >> bt[i][j];
  for (long long int i = (long long int)0; i < (long long int)(3); i++) {
    for (long long int j = (long long int)0; j < (long long int)(3); j++) {
      long long int toa = at[i][j] - 1, tob = bt[i][j] - 1;
      mp[{i, j}].push_back({toa, tob});
    }
  }
  start = make_pair(a, b);
  dfs(make_pair(a, b), make_pair(-1ll, -1ll));
  std::vector<pair<long long int, long long int>> temp;
  pair<long long int, long long int> t = vals.back();
  long long int wt = 0, vt = 0;
  while (par[t] != make_pair(-1ll, -1ll)) {
    temp.push_back(par[t]);
    t = par[t];
  }
  reverse(temp.begin(), temp.end());
  for (long long int i = (long long int)0;
       i < (long long int)(min((long long int)temp.size(), k)); i++) {
    auto z = score(temp[i].first, temp[i].second);
    wt += z.first;
    vt += z.second;
  }
  k = k - min((long long int)(temp.size()), k);
  long long int cnt = k / cyc, wa = 0, wb = 0;
  reverse(vals.begin(), vals.end());
  for (auto p : vals) {
    auto z = score(p.first, p.second);
    wa += z.first;
    wb += z.second;
  }
  wt += cnt * wa;
  vt += cnt * wb;
  wa = 0;
  wb = 0;
  for (long long int i = (long long int)0; i < (long long int)(k % cyc); i++) {
    auto z = score(vals[i].first, vals[i].second);
    wa += z.first;
    wb += z.second;
  }
  wt += wa;
  vt += wb;
  cout << wt << ' ' << vt << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  clock_t z = clock();
  for (long long int tes = (long long int)0; tes < (long long int)(test);
       tes++) {
    solve();
  }
  fprintf(stderr, "Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
  return 0;
}
