#include <bits/stdc++.h>
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
using namespace std;
int n, p[105], c[105], k, s = 0, ans = 0, a[3][20005];
int main() {
  n = read(), k = read();
  for (int i = 0; i < n; i++) p[i] = read();
  for (int i = 0; i < n; i++) c[i] = read();
  for (int i = (2 * n) - 1; i >= n; i--) c[i] = read();
  for (int i = (2 * n) - 1; i >= n; i--) p[i] = read();
  bool flag = 1;
  for (int i = 0; i < 2 * n; i++) {
    if (c[i] == 0) flag = 0;
    if (c[i] == p[i] && p[i] != 0) {
      if (i < n)
        a[0][++ans] = c[i], a[1][ans] = 1, a[2][ans] = i + 1;
      else
        a[0][++ans] = c[i], a[1][ans] = 4, a[2][ans] = 2 * n - i;
      --k, c[i] = flag = 0;
    }
  }
  if (flag) puts("-1"), exit(0);
  while (k > 0) {
    for (; c[s] == 0 || c[(s + 1) % (2 * n)] != 0;
         s = (s + 2 * n - 1) % (2 * n))
      ;
    while (c[(s + 1) % (2 * n)] == 0 && k > 0) {
      int tmp = (s + 1) % (2 * n);
      if (c[tmp] == 0) {
        if (tmp < n)
          a[0][++ans] = c[s], a[1][ans] = 2, a[2][ans] = tmp + 1;
        else
          a[0][++ans] = c[s], a[1][ans] = 3, a[2][ans] = 2 * n - tmp;
        swap(c[s], c[tmp]);
        s = (s + 1) % (2 * n);
      }
      if (c[s] == p[s] && p[s] != 0) {
        if (s < n)
          a[0][++ans] = c[s], a[1][ans] = 1, a[2][ans] = s + 1;
        else
          a[0][++ans] = c[s], a[1][ans] = 4, a[2][ans] = 2 * n - s;
        --k, c[s] = 0;
        break;
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= ans; i++)
    printf("%d %d %d\n", a[0][i], a[1][i], a[2][i]);
  return 0;
}
