#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
void test_case() {
  long long k, a, b;
  cin >> k >> a >> b;
  long long al[3][3], bob[3][3];
  --a, --b;
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < 3; j++) {
      long long x;
      cin >> x;
      --x;
      al[i][j] = x;
    }
  for (long long i = 0; i < 3; i++)
    for (long long j = 0; j < 3; j++) {
      long long x;
      cin >> x;
      --x;
      bob[i][j] = x;
    }
  vector<pair<long long, long long> > pre;
  pre.push_back({a, b});
  long long alice = 0, bo = 0;
  long long ta = 0, tb = 0, cy;
  while (1) {
    long long na = al[a][b], nb = bob[a][b], idx = -1;
    for (long long i = 0; i < (long long)pre.size(); i++) {
      if (pre[i] == make_pair(na, nb)) {
        idx = i;
        break;
      }
    }
    if (idx == -1) {
      pre.push_back({na, nb});
      a = na, b = nb;
    } else {
      for (long long i = 0; i < min(k, idx); i++) {
        if (pre[i].first == pre[i].second) continue;
        if (pre[i].first == 2 && pre[i].second == 1)
          alice++;
        else if (pre[i].first == 1 && pre[i].second == 0)
          alice++;
        else if (pre[i].first == 0 && pre[i].second == 2)
          alice++;
        else
          bo++;
      }
      k -= min(k, idx);
      if (k > 0) {
        for (long long i = idx; i < (long long)pre.size(); i++) {
          if (pre[i].first == pre[i].second) continue;
          if (pre[i].first == 2 && pre[i].second == 1)
            ta++;
          else if (pre[i].first == 1 && pre[i].second == 0)
            ta++;
          else if (pre[i].first == 0 && pre[i].second == 2)
            ta++;
          else
            tb++;
        }
        cy = pre.size() - idx;
        alice += (ta * (k / cy));
        bo += (tb * (k / cy));
        long long in = k % cy;
        for (long long i = idx; i < idx + in; i++) {
          if (pre[i].first == pre[i].second) continue;
          if (pre[i].first == 2 && pre[i].second == 1)
            alice++;
          else if (pre[i].first == 1 && pre[i].second == 0)
            alice++;
          else if (pre[i].first == 0 && pre[i].second == 2)
            alice++;
          else
            bo++;
        }
      }
      break;
    }
  }
  cout << alice << " " << bo << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) test_case();
}
