#include <bits/stdc++.h>
using namespace std;
int now[10][100], dx[100], dy[100], n, k, q[200010][3], head, tail, res;
void push(int a, int b, int c) {
  q[tail][0] = a, q[tail][1] = b, q[tail][2] = c;
  tail++;
}
void up(int x, int y) {
  push(now[x][y], x - 1, y);
  swap(now[x][y], now[x - 1][y]);
}
void down(int x, int y) {
  push(now[x][y], x + 1, y);
  swap(now[x][y], now[x + 1][y]);
}
void left(int x, int y) {
  push(now[x][y], x, y - 1);
  swap(now[x][y], now[x][y - 1]);
}
void right(int x, int y) {
  push(now[x][y], x, y + 1);
  swap(now[x][y], now[x][y + 1]);
}
void park() {
  int i, t;
  for (i = 1; i <= n; i++) {
    t = now[2][i];
    if (i == dy[t] and dx[t] == 1) up(2, i), res--;
  }
  for (i = 1; i <= n; i++) {
    t = now[3][i];
    if (i == dy[t] and dx[t] == 4) down(3, i), res--;
  }
}
void init() {
  int i, j;
  scanf("%d%d", &n, &k);
  res = k;
  for (i = 1; i <= 4; i++)
    for (j = 1; j <= n; j++) scanf("%d", now[i] + j);
  for (i = 1; i <= 4; i += 3)
    for (j = 1; j <= n; j++)
      if (now[i][j]) dx[now[i][j]] = i, dy[now[i][j]] = j, now[i][j] = 0;
  park();
}
void spin() {
  int i;
  for (i = n - 1; i; i--)
    if (now[2][i] and now[2][i + 1] == 0 and (rand() & 1)) right(2, i);
  if (now[3][1] and now[2][1] == 0 and (rand() & 1)) up(3, 1);
  for (i = 2; i <= n; i++)
    if (now[3][i] and now[3][i - 1] == 0 and (rand() & 1)) left(3, i);
  if (now[2][n] and now[3][n] == 0 and (rand() & 1)) down(2, n);
}
void show() {
  for (printf("%d\n", tail - head); head ^ tail; head++)
    printf("%d %d %d\n", q[head][0], q[head][1], q[head][2]);
}
int main() {
  int i;
  init();
  for (i = 1; i <= n; i++)
    if (now[2][i] == 0 or now[3][i] == 0) break;
  if (i > n) {
    printf("-1");
    return 0;
  }
  while (res) spin(), park();
  show();
  return 0;
}
