#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int N = 3e5 + 5;
int x[5][5], y[5][5];
bool vis[5][5];
int win(int x, int y) {
  if (x == 3 && y == 2) return 1;
  if (x == 2 && y == 1) return 1;
  if (x == 1 && y == 3) return 1;
  return 0;
}
vector<pair<int, int> > v;
int whoX, whoY;
void dfs(int a, int b) {
  v.push_back({a, b});
  vis[a][b] = 1;
  int newX = x[a][b], newY = y[a][b];
  if (vis[newX][newY]) {
    whoX = newX, whoY = newY;
    return;
  }
  dfs(newX, newY);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long k, a, b;
  cin >> k >> a >> b;
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> x[i][j];
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> y[i][j];
    }
  }
  dfs(a, b);
  vector<int> line, cycle;
  bool flag = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    if (!flag && !(v[i].first == whoX && v[i].second == whoY)) {
      line.push_back(win(v[i].first, v[i].second)
                         ? 1
                         : (win(v[i].second, v[i].first) ? -1 : 0));
    } else
      flag = 1;
    if (flag) {
      cycle.push_back(win(v[i].first, v[i].second)
                          ? 1
                          : (win(v[i].second, v[i].first) ? -1 : 0));
    }
  }
  long long alice = 0, bob = 0;
  for (int i = 0; i < (int)line.size() && k; i++) {
    if (line[i] > 0)
      alice++;
    else if (line[i] < 0)
      bob++;
    k--;
  }
  long long cycleAlice = 0, cycleBob = 0;
  for (auto i : cycle) {
    if (i > 0)
      cycleAlice++;
    else if (i < 0)
      cycleBob++;
  }
  long long cycles = k / (long long)cycle.size();
  long long left = k % (long long)cycle.size();
  alice += cycles * cycleAlice, bob += cycles * cycleBob;
  for (int i = 0; i < left; i++) {
    if (cycle[i] > 0)
      alice++;
    else if (cycle[i] < 0)
      bob++;
  }
  cout << alice << " " << bob;
  return 0;
}
