#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 51;
struct Item {
  int c, x, y;
};
vector<Item> v;
int n, flg, cx, cy;
int g[5][MAXN], prvx[5][MAXN], prvy[5][MAXN], nxtx[5][MAXN], nxty[5][MAXN];
inline int read() {
  register int num = 0, neg = 1;
  register char ch = getchar();
  while (!isdigit(ch) && ch != '-') {
    ch = getchar();
  }
  if (ch == '-') {
    neg = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch - '0');
    ch = getchar();
  }
  return num * neg;
}
inline void move() {
  for (register int i = 1; i <= n; i++) {
    g[1][i] == g[2][i] && g[1][i] ? v.emplace_back((Item){g[1][i], 1, i}),
        g[2][i] = 0               : 1;
    g[3][i] == g[4][i] && g[4][i] ? v.emplace_back((Item){g[4][i], 4, i}),
        g[3][i] = 0               : 1;
  }
}
inline void rotate() {
  int tx = cx, ty = cy, px = prvx[cx][cy], py = prvy[cx][cy], u, v;
  for (register int i = px, j = py; i != tx || j != ty; i = u, j = v) {
    if (g[i][j]) {
      ::v.emplace_back((Item){g[i][j], nxtx[i][j], nxty[i][j]});
      swap(g[i][j], g[nxtx[i][j]][nxty[i][j]]);
    }
    u = prvx[i][j], v = prvy[i][j];
  }
  cx = nxtx[tx][ty], cy = nxty[tx][ty];
}
int main() {
  n = read(), read();
  for (register int i = 1; i <= 4; i++) {
    for (register int j = 1; j <= n; j++) {
      g[i][j] = read();
    }
  }
  for (register int i = 1; i <= n; i++) {
    prvx[2][i] = nxtx[2][i] = 2, prvx[3][i] = nxtx[3][i] = 3;
    prvy[2][i] = nxty[3][i] = i - 1, prvy[3][i] = nxty[2][i] = i + 1;
  }
  prvx[2][1] = 3, prvy[2][1] = 1, nxtx[2][n] = 3, nxty[2][n] = n;
  prvx[3][n] = 2, prvy[3][n] = n, nxtx[3][1] = 2, nxty[3][1] = 1;
  move();
  for (register int i = 1; i <= n; i++) {
    !g[2][i] ? cx = 2, cy = i : 1, !g[3][i] ? cx = 3, cy = i : 1;
  }
  if (!cx) {
    return puts("-1"), 0;
  }
  for (register int i = 1; i <= 2 * n; i++) {
    rotate(), move();
  }
  printf("%d\n", v.size());
  for (auto i : v) {
    printf("%d %d %d\n", i.c, i.x, i.y);
  }
}
