#include <bits/stdc++.h>
using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");
int n, k;
int lot[51][51];
struct move_car {
  int lin, col;
  int val;
} sol[20001];
int cnt;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) cin >> lot[i][j];
  for (int t = 1; t <= 200; t++) {
    int lin = 0, col = 0;
    for (int j = 1; j <= n; j++) {
      if (lot[2][j] == 0) {
        lin = 2;
        col = j;
        break;
      }
      if (lot[3][j] == 0) {
        lin = 3;
        col = j;
        break;
      }
    }
    for (int j = 1; j <= n; j++) {
      if (lot[2][j] == lot[1][j] && lot[2][j] != 0) {
        move_car mc;
        mc.val = lot[2][j];
        mc.lin = 1;
        mc.col = j;
        sol[++cnt] = mc;
        lot[2][j] = 0;
      }
    }
    for (int j = 1; j <= n; j++) {
      if (lot[3][j] == lot[4][j] && lot[3][j] != 0) {
        move_car mc;
        mc.val = lot[3][j];
        mc.lin = 4;
        mc.col = j;
        sol[++cnt] = mc;
        lot[3][j] = 0;
      }
    }
    if (lin != 0) {
      for (int i = 1; i < 2 * n; i++) {
        int nlin, ncol;
        if (lin == 2) {
          if (col == n) {
            nlin = 3;
            ncol = n;
          } else {
            nlin = 2;
            ncol = col + 1;
          }
        } else {
          if (col == 1) {
            nlin = 2;
            ncol = 1;
          } else {
            nlin = 3;
            ncol = col - 1;
          }
        }
        if (lot[nlin][ncol] != 0) {
          move_car mc;
          mc.val = lot[nlin][ncol];
          mc.lin = lin;
          mc.col = col;
          sol[++cnt] = mc;
          lot[lin][col] = lot[nlin][ncol];
          lot[nlin][ncol] = 0;
        }
        lin = nlin;
        col = ncol;
      }
    }
  }
  for (int i = 2; i <= 3; i++)
    for (int j = 1; j <= n; j++)
      if (lot[i][j] != 0) {
        cout << -1;
        return 0;
      }
  cout << cnt << "\n";
  for (int i = 1; i <= cnt; i++) {
    cout << sol[i].val << " " << sol[i].lin << " " << sol[i].col << "\n";
  }
  return 0;
}
