#include <bits/stdc++.h>
using namespace std;
const int N = 5, M = 55, P = 2e4 + 10, UP = 2e4;
int n, m;
int mp[N][M];
struct node {
  int x, y, id;
  node() {}
  node(int a, int b, int c) : x(a), y(b), id(c) {}
  void out() { printf("%d %d %d\n", id, x, y); }
} opt[P];
int tot, cnt, top;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &mp[i][j]);
  int sx = 2, sy = 1, fx, fy, tx, ty;
  while (top <= (UP << 1) && tot <= UP && cnt != m) {
    fx = sx;
    fy = (fx == 2 ? sy + 1 : sy - 1);
    if (fy > n) ++fx, --fy;
    if (fy < 1) --fx, ++fy;
    ty = fy;
    tx = (fx == 2 ? 1 : 4);
    if (mp[fx][fy]) {
      if (mp[tx][ty] == mp[fx][fy])
        opt[++tot] = node(tx, ty, mp[fx][fy]), ++cnt, mp[fx][fy] = 0;
      else if (!mp[sx][sy])
        opt[++tot] = node(sx, sy, mp[fx][fy]), swap(mp[fx][fy], mp[sx][sy]);
    }
    sx = fx;
    sy = fy;
    ++top;
  }
  if (cnt != m || tot > UP)
    puts("-1");
  else {
    printf("%d\n", tot);
    for (int i = 1; i <= tot; i++) opt[i].out();
  }
  return 0;
}
