#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
int adjA[4][4];
int adjB[4][4];
int32_t main() {
  ll k;
  int a, b;
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) cin >> adjA[i][j];
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) cin >> adjB[i][j];
  map<ii, int> mp;
  vector<ii> score;
  score.push_back(ii(0, 0));
  int idx = 1;
  pair<int, int> pos = make_pair(a, b);
  ll a1 = 0, a2 = 0;
  while (k) {
    a = pos.first, b = pos.second;
    if (mp.find(pos) != mp.end()) {
      ll r = idx - 1;
      ll l = mp[pos] - 1;
      ll ra = score[r].first - score[l].first;
      ll rb = score[r].second - score[l].second;
      ll q = k / (r - l);
      ll rest = k % (r - l);
      a1 += ra * q;
      a2 += rb * q;
      a1 += score[l + rest].first - score[l].first;
      a2 += score[l + rest].second - score[l].second;
      break;
    }
    if (a == b)
      score.push_back(score.back());
    else if ((a == 3 and b == 2) or (a == 2 and b == 1) or (a == 1 and b == 3))
      score.push_back(ii(score.back().first + 1, score.back().second));
    else
      score.push_back(ii(score.back().first, score.back().second + 1));
    mp[pos] = idx++;
    pos = ii(adjA[a][b], adjB[a][b]);
    --k;
  }
  a1 += score.back().first;
  a2 += score.back().second;
  cout << a1 << " " << a2 << endl;
}
