#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int k, staA, staB;
  cin >> k >> staA >> staB;
  vector<vector<int> > a(3);
  vector<vector<int> > b(3);
  vector<vector<pair<int, int> > > arr(3);
  vector<vector<int> > was(3);
  vector<vector<int> > was2(3);
  for (int i = 0; i < 3; i++) {
    arr[i].resize(3);
    a[i].resize(3);
    b[i].resize(3);
    was[i].resize(3, 0);
    was2[i].resize(3, 0);
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> b[i][j];
      b[i][j]--;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      arr[i][j] = make_pair(a[i][j], b[i][j]);
    }
  }
  staA--;
  staB--;
  long long int tota = 0;
  long long int totab = 0;
  if (k < 200) {
    while (k != 0) {
      k--;
      staA++;
      staB++;
      if (staA == 3) {
        if (staB == 1) {
          totab++;
        } else {
          if (staB == 2) {
            tota++;
          }
        }
      } else {
        if (staA == 1) {
          if (staB == 3) {
            tota++;
          } else {
            if (staB == 2) {
              totab++;
            }
          }
        } else {
          if (staB == 1) {
            tota++;
          } else {
            if (staB == 3) {
              totab++;
            }
          }
        }
      }
      staA--;
      staB--;
      pair<int, int> tem = arr[staA][staB];
      staA = tem.first;
      staB = tem.second;
    }
    cout << tota << " " << totab;
    return 0;
  }
  was[staA][staB] = 1;
  tota = 0;
  totab = 0;
  while (true) {
    k--;
    staA++;
    staB++;
    if (staA == 3) {
      if (staB == 1) {
        totab++;
      } else {
        if (staB == 2) {
          tota++;
        }
      }
    } else {
      if (staA == 1) {
        if (staB == 3) {
          tota++;
        } else {
          if (staB == 2) {
            totab++;
          }
        }
      } else {
        if (staB == 1) {
          tota++;
        } else {
          if (staB == 3) {
            totab++;
          }
        }
      }
    }
    staA--;
    staB--;
    pair<int, int> tem = arr[staA][staB];
    staA = tem.first;
    staB = tem.second;
    if (was[staA][staB] == 1) {
      break;
    }
    was[staA][staB] = 1;
  }
  int yy = staA;
  int gg = staB;
  long long int j = 0, q = 0;
  int len = 0;
  was2[yy][gg] = 1;
  while (true) {
    len++;
    yy++;
    gg++;
    if (yy == 3) {
      if (gg == 1) {
        q++;
      } else {
        if (gg == 2) {
          j++;
        }
      }
    } else {
      if (yy == 1) {
        if (gg == 3) {
          j++;
        } else {
          if (gg == 2) {
            q++;
          }
        }
      } else {
        if (gg == 1) {
          j++;
        } else {
          if (gg == 3) {
            q++;
          }
        }
      }
    }
    yy--;
    gg--;
    pair<int, int> tem = arr[yy][gg];
    yy = tem.first;
    gg = tem.second;
    if (was2[yy][gg] == 1) {
      break;
    }
    was2[yy][gg] = 1;
  }
  while (k != 0) {
    k--;
    staA++;
    staB++;
    if (staA == 3) {
      if (staB == 1) {
        totab++;
      } else {
        if (staB == 2) {
          tota++;
        }
      }
    } else {
      if (staA == 1) {
        if (staB == 3) {
          tota++;
        } else {
          if (staB == 2) {
            totab++;
          }
        }
      } else {
        if (staB == 1) {
          tota++;
        } else {
          if (staB == 3) {
            totab++;
          }
        }
      }
    }
    staA--;
    staB--;
    pair<int, int> tem = arr[staA][staB];
    staA = tem.first;
    staB = tem.second;
    if (k / len > 0) {
      tota += (k / len) * j;
      totab += (k / len) * q;
      k = k % len;
    }
  }
  cout << tota << " " << totab;
  return 0;
}
