#include <bits/stdc++.h>
using namespace std;
long long k, l, g = 0, h = 0;
int a, b, p[3][3], q[3][3], t, u, v, c;
vector<pair<int, int> > s;
bool con;
int gg(int a, int b) {
  if (a == b + 1 || a == b - 2) return 1;
  return 0;
}
void sim(int x, int t, int u) {
  while (x > 0) {
    g += gg(t, u);
    h += gg(u, t);
    v = t;
    t = p[t][u];
    u = q[v][u];
    x--;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> k >> a >> b;
  a--, b--;
  for (int i = 0; i < (3); i++)
    for (int j = 0; j < (3); j++) cin >> p[i][j];
  for (int i = 0; i < (3); i++)
    for (int j = 0; j < (3); j++) cin >> q[i][j];
  for (int i = 0; i < (3); i++)
    for (int j = 0; j < (3); j++) q[i][j]--, p[i][j]--;
  s.push_back({a, b});
  t = p[a][b], u = q[a][b];
  while (true) {
    con = false;
    for (int i = 0; i < (s.size()); i++) {
      if (s[i].first == t && s[i].second == u) con = true;
    }
    if (con)
      break;
    else {
      s.push_back({t, u});
      v = t;
      t = p[t][u];
      u = q[v][u];
    }
    con = false;
  }
  for (int i = 0; i < (s.size()); i++) {
    if (s[i].first == t && s[i].second == u) c = s.size() - i;
  }
  if (k < 10000) {
    sim(k, a, b);
  } else {
    l = (k - s.size() + c) / c;
    sim(c, t, u);
    g *= l;
    h *= l;
    sim(s.size() - c, a, b);
    sim((k - s.size() + c) % c, t, u);
  }
  cout << g << " " << h << endl;
}
