#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int k;
  int sx, sy;
  scanf("%I64d%d%d", &k, &sx, &sy);
  --sx;
  --sy;
  vector<vector<pair<int, int>>> g(3, vector<pair<int, int>>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> g[i][j].first;
      g[i][j].first--;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> g[i][j].second;
      g[i][j].second--;
    }
  }
  vector<vector<int>> dist(3, vector<int>(3, -1));
  dist[sx][sy] = 0;
  int d = 1;
  int x = g[sx][sy].first, y = g[sx][sy].second;
  while (dist[x][y] == -1) {
    dist[x][y] = d++;
    int tx = x, ty = y;
    x = g[tx][ty].first, y = g[tx][ty].second;
  }
  long long int cycleLen = d - dist[x][y];
  long long int prefix = dist[x][y];
  int cx = x, cy = y;
  long long int prefixAScoreChange = 0, prefixBScoreChange = 0;
  int q = 0;
  x = sx, y = sy;
  while (x != cx || y != cy) {
    q++;
    if (x == 0) {
      if (y == 1) prefixBScoreChange++;
      if (y == 2) prefixAScoreChange++;
    } else if (x == 1) {
      if (y == 0) prefixAScoreChange++;
      if (y == 2) prefixBScoreChange++;
    } else if (x == 2) {
      if (y == 0) prefixBScoreChange++;
      if (y == 1) prefixAScoreChange++;
    }
    if (q == k) {
      cout << prefixAScoreChange << " " << prefixBScoreChange << endl;
      return 0;
    }
    int tx = x, ty = y;
    x = g[tx][ty].first, y = g[tx][ty].second;
  }
  long long int cycleAScoreChange = 0, cycleBScoreChange = 0;
  bool started = false;
  while (!started || !(x == cx && y == cy)) {
    started = true;
    if (x == 0) {
      if (y == 1) cycleBScoreChange++;
      if (y == 2) cycleAScoreChange++;
    } else if (x == 1) {
      if (y == 0) cycleAScoreChange++;
      if (y == 2) cycleBScoreChange++;
    } else if (x == 2) {
      if (y == 0) cycleBScoreChange++;
      if (y == 1) cycleAScoreChange++;
    }
    int tx = x, ty = y;
    x = g[tx][ty].first, y = g[tx][ty].second;
  }
  long long int extraAScoreChange = 0, extraBScoreChange = 0;
  q = 0;
  x = cx, y = cy;
  while (q < (k - prefix) % cycleLen) {
    q++;
    if (x == 0) {
      if (y == 1) extraBScoreChange++;
      if (y == 2) extraAScoreChange++;
    } else if (x == 1) {
      if (y == 0) extraAScoreChange++;
      if (y == 2) extraBScoreChange++;
    } else if (x == 2) {
      if (y == 0) extraBScoreChange++;
      if (y == 1) extraAScoreChange++;
    }
    int tx = x, ty = y;
    x = g[tx][ty].first, y = g[tx][ty].second;
  }
  long long int ansA = prefixAScoreChange +
                       cycleAScoreChange * ((k - prefix) / cycleLen) +
                       extraAScoreChange;
  long long int ansB = prefixBScoreChange +
                       cycleBScoreChange * ((k - prefix) / cycleLen) +
                       extraBScoreChange;
  cout << ansA << " " << ansB << endl;
  return 0;
}
