#include <bits/stdc++.h>
using namespace std;
int z() {
  int z;
  scanf("%d", &z);
  return z;
}
long long Z() {
  long long Z;
  scanf("%I64d", &Z);
  return Z;
}
const int _ = 200200;
int n, m, k;
int a[5][200];
struct STC {
  int i, r, c;
} p[20020];
int top;
int b[5][200];
struct mov {
  int br, bc, ar, ac;
} q[2000];
int qn;
void init() {
  q[qn++] = (mov){3, 1, 2, 1};
  for (int i = 2; i <= n; i++) {
    q[qn++] = (mov){2, i - 1, 2, i};
  }
  q[qn++] = (mov){2, n, 3, n};
  for (int i = n - 1; i; i--) {
    q[qn++] = (mov){3, i + 1, 3, i};
  }
}
void rot() {
  for (int i = 1; i <= n; i++) {
    b[2][i] = a[2][i];
    b[3][i] = a[3][i];
  }
  int st = 0;
  for (int i = 0; i < qn; i++) {
    int ar = q[i].ar;
    int ac = q[i].ac;
    if (a[ar][ac] == 0) {
      st = i;
      break;
    }
  }
  for (int i = 0; i < qn; i++) {
    int j = ((st - i) % qn + qn) % qn;
    a[q[j].ar][q[j].ac] = b[q[j].br][q[j].bc];
    if (b[q[j].br][q[j].bc]) {
      p[++top] = (STC){b[q[j].br][q[j].bc], q[j].ar, q[j].ac};
    }
  }
}
void get() {
  int t = k;
  for (int i = 1; i <= n; i++) {
    if (a[1][i] && a[1][i] == a[2][i]) {
      p[++top] = (STC){a[2][i], 1, i};
      a[2][i] = 0;
      t--;
    }
    if (a[3][i] && a[3][i] == a[4][i]) {
      p[++top] = (STC){a[3][i], 4, i};
      a[3][i] = 0;
      t--;
    }
  }
  if (t == n * 2) {
    cout << -1 << endl;
    return;
  }
  while (t) {
    for (int i = 1; i <= n; i++) {
      if (a[1][i] && a[1][i] == a[2][i]) {
        p[++top] = (STC){a[2][i], 1, i};
        a[2][i] = 0;
        t--;
      }
      if (a[3][i] && a[3][i] == a[4][i]) {
        p[++top] = (STC){a[3][i], 4, i};
        a[3][i] = 0;
        t--;
      }
    }
    if (t) rot();
  }
  printf("%d\n", top);
  for (int i = 1; i <= top; i++) {
    printf("%d %d %d\n", p[i].i, p[i].r, p[i].c);
  }
}
int main() {
  n = z();
  k = z();
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = z();
    }
  }
  init();
  get();
}
