#include <bits/stdc++.h>
using namespace std;
const int MAX = 110;
int G[5][MAX];
int n, k;
struct movi {
  int i;
  int j;
  int car;
};
movi M[100010];
int impossible() {
  if (k < 2 * n) return 0;
  for (int j = 1; j <= n; j++) {
    if (G[2][j] == G[1][j]) return 0;
  }
  for (int j = 1; j <= n; j++) {
    if (G[3][j] == G[4][j]) return 0;
  }
  return 1;
}
int moves = 0;
void check() {
  for (int j = 1; j <= n; j++) {
    if (G[2][j] == G[1][j] && G[2][j] != 0) {
      movi m;
      m.i = 1;
      m.j = j;
      m.car = G[2][j];
      M[moves] = m;
      moves++;
      G[2][j] = 0;
    }
  }
  for (int j = 1; j <= n; j++) {
    if (G[3][j] == G[4][j] && G[3][j] != 0) {
      movi m;
      m.i = 4;
      m.j = j;
      m.car = G[3][j];
      M[moves] = m;
      moves++;
      G[3][j] = 0;
    }
  }
}
int nexti(int i, int j) {
  if (i == 2) {
    if (j == 1) return 3;
    return 2;
  }
  if (i == 3) {
    if (j == n) return 2;
    return 3;
  }
}
int nextj(int i, int j) {
  if (i == 2) {
    if (j == 1) return 1;
    return j - 1;
  }
  if (i == 3) {
    if (j == n) return n;
    return j + 1;
  }
}
void rotate() {
  int ib, jb;
  for (int j = 1; j <= n; j++) {
    if (G[2][j] == 0) {
      ib = 2;
      jb = j;
    }
    if (G[3][j] == 0) {
      ib = 3;
      jb = j;
    }
  }
  int it = ib, jt = jb;
  while (nexti(it, jt) != ib || nextj(it, jt) != jb) {
    int ni = nexti(it, jt), nj = nextj(it, jt);
    if (G[ni][nj] != 0) {
      movi m;
      m.i = it;
      m.j = jt;
      m.car = G[ni][nj];
      M[moves] = m;
      moves++;
      G[it][jt] = m.car;
      G[ni][nj] = 0;
    }
    it = ni, jt = nj;
  }
}
int done() {
  for (int j = 1; j <= n; j++) {
    if (G[2][j] != 0 || G[3][j] != 0) return 0;
  }
  return 1;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", &G[i][j]);
    }
  }
  if (impossible()) {
    printf("-1\n");
    return 0;
  }
  while (!done()) {
    check();
    if (done()) continue;
    rotate();
  }
  printf("%d\n", moves);
  for (int i = 0; i < moves; i++) {
    movi m = M[i];
    printf("%d %d %d\n", m.car, m.i, m.j);
  }
}
