#include <bits/stdc++.h>
using namespace std;
long long int a[5][5], b[5][5], res[5][5], sum1[20], sum2[20];
vector<pair<long long int, long long int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int k, x, y, f = 0;
  cin >> k >> x >> y;
  for (long long int i = 1; i <= 3; i++)
    for (long long int j = 1; j <= 3; j++) cin >> a[i][j];
  for (long long int i = 1; i <= 3; i++)
    for (long long int j = 1; j <= 3; j++) cin >> b[i][j];
  long long int i = 1;
  while (i <= k) {
    if (res[x][y]) {
      long long int t = res[x][y];
      long long int len = i - t;
      k -= t - 1;
      sum1[0] = sum1[t - 1] + (sum1[i - 1] - sum1[t - 1]) * (k / len) +
                (sum1[t + k % len - 1] - sum1[t - 1]);
      sum2[0] = sum2[t - 1] + (sum2[i - 1] - sum2[t - 1]) * (k / len) +
                (sum2[t + k % len - 1] - sum2[t - 1]);
      f = 1;
      break;
    }
    res[x][y] = i;
    sum1[i] = sum1[i - 1];
    sum2[i] = sum2[i - 1];
    if (x == 1 && y == 2)
      sum2[i]++;
    else if (x == 1 && y == 3)
      sum1[i]++;
    else if (x == 2 && y == 1)
      sum1[i]++;
    else if (x == 2 && y == 3)
      sum2[i]++;
    else if (x == 3 && y == 1)
      sum2[i]++;
    else if (x == 3 && y == 2)
      sum1[i]++;
    long long int x1 = a[x][y], y1 = b[x][y];
    x = x1;
    y = y1;
    i++;
  }
  if (f == 0) {
    sum1[0] = sum1[i - 1];
    sum2[0] = sum2[i - 1];
  }
  cout << sum1[0] << " " << sum2[0];
}
