#include <bits/stdc++.h>
using namespace std;
struct aka {
  int i, r, c;
} ans[30005];
int a[10000];
int b[10000];
int n, k;
int sum = 0;
int tot = 0;
void fork() {
  for (int i = 1; i <= 2 * n; i++) {
    if (b[i] != 0 && a[i] == b[i]) {
      int x = i, y = 1;
      if (x > n) {
        x = 2 * n - i + 1;
        y = 4;
      }
      ans[tot].i = b[i];
      ans[tot].r = y;
      ans[tot].c = x;
      tot++;
      b[i] = 0;
      sum++;
    }
  }
}
int main() {
  int flag = 0;
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 2 * n; i >= n + 1; i--) cin >> b[i];
  for (int i = 2 * n; i >= n + 1; i--) cin >> a[i];
  while (tot <= 20000) {
    int kkk = tot;
    fork();
    if (sum == k) break;
    for (int i = 2; i <= 2 * n; i++) {
      fork();
      if (b[i] != 0) {
        if (b[i - 1] == 0) {
          int x, y;
          if (i - 1 > n) {
            x = 2 * n - (i - 1) + 1;
            y = 3;
          } else {
            x = i - 1;
            y = 2;
          }
          ans[tot].i = b[i];
          ans[tot].r = y;
          ans[tot].c = x;
          tot++;
          swap(b[i], b[i - 1]);
        }
      }
    }
    if (b[1] != 0 && b[2 * n] == 0) {
      ans[tot].i = b[1];
      ans[tot].r = 3;
      ans[tot].c = 1;
      swap(b[1], b[2 * n]);
      tot++;
    }
    if (kkk == tot) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "-1" << endl;
  else {
    cout << tot << endl;
    for (int i = 0; i < tot; i++) {
      cout << ans[i].i << " " << ans[i].r << " " << ans[i].c << endl;
    }
  }
}
