#include <bits/stdc++.h>
using namespace std;
struct arr {
  int s, x, y;
} ans[2000005];
struct P {
  int x, y;
} k[14][5005];
int n, m, a[15][5005], t = 0, Q = 0;
inline bool move() {
  for (int i = 1; i <= n; i++)
    if (a[2][i] != 0 && a[2][i] == a[1][i])
      Q++, a[2][i] = 0, ans[++t] = (arr){a[1][i], 1, i};
  for (int i = 1; i <= n; i++)
    if (a[3][i] != 0 && a[3][i] == a[4][i])
      Q++, a[3][i] = 0, ans[++t] = (arr){a[4][i], 4, i};
  return Q == m;
}
int o = 0;
inline void dfs() {
  if (move()) return;
  P p, pp;
  bool Flag = 0;
  for (int i = 1; i <= n; i++)
    if (a[2][i] || a[3][i]) Flag = 1;
  if (!Flag) return;
  bool flag = 0;
  for (int i = 1; i <= n; i++)
    if (!a[2][i])
      p.x = 2, p.y = i, flag = 1;
    else if (!a[3][i])
      p.x = 3, p.y = i, flag = 1;
  if (!flag) {
    printf("-1\n");
    exit(0);
  }
  int x = k[p.x][p.y].x, y = k[p.x][p.y].y;
  pp = p;
  while (1) {
    if (pp.x == x && pp.y == y) break;
    if (a[x][y] != 0) ans[++t] = (arr){a[x][y], p.x, p.y};
    a[p.x][p.y] = a[x][y];
    a[x][y] = 0;
    p.x = x, p.y = y;
    x = k[p.x][p.y].x, y = k[p.x][p.y].y;
  }
  a[p.x][p.y] = 0;
  if (t >= 10010) return;
  dfs();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i < n; i++) k[2][i] = (P){2, i + 1};
  k[2][n] = (P){3, n};
  for (int i = n; i > 1; i--) k[3][i] = (P){3, i - 1};
  k[3][1] = (P){2, 1};
  dfs();
  printf("%d\n", t);
  for (int i = 1; i <= t; i++)
    printf("%d %d %d\n", ans[i].s, ans[i].x, ans[i].y);
  return 0;
}
