#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int R1[n + 2], R2[n + 2], A[n + 2], B[n + 2];
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == 1) cin >> R1[j];
      if (i == 2) cin >> A[j];
      if (i == 3) cin >> B[j];
      if (i == 4) cin >> R2[j];
    }
  }
  int zero = -1, row;
  for (int i = 1; i <= n; i++) {
    if (A[i] == 0) {
      row = 2;
      zero = i;
      break;
    }
    if (B[i] == 0) {
      row = 3;
      zero = i;
      break;
    }
  }
  vector<tuple<int, int, int>> ans;
  if (zero == -1) {
    int tem = 0;
    for (int i = 1; i <= n; i++) {
      if (R1[i] == A[i]) {
        tem = 1;
        zero = i;
        row = 2;
        A[i] = 0;
        ans.push_back(make_tuple(R1[i], 1, i));
        k--;
        break;
      }
      if (R2[i] == B[i]) {
        tem = 1;
        zero = i;
        row = 3;
        B[i] = 0;
        ans.push_back(make_tuple(R2[i], 4, i));
        k--;
        break;
      }
    }
    if (tem == 0) {
      cout << -1;
      return 0;
    }
  }
  while (k) {
    while (row == 2 && k) {
      if (zero == n) {
        int car = B[n];
        if (car == R2[n] && car) {
          ans.push_back(make_tuple(car, 4, n));
          k--;
        } else if (car == R1[n] && car) {
          ans.push_back(make_tuple(car, 2, n));
          ans.push_back(make_tuple(car, 1, n));
          k--;
        } else if (car) {
          A[n] = car;
          ans.push_back(make_tuple(car, 2, n));
        }
        B[n] = 0;
        row = 3;
      } else {
        int car = A[zero + 1];
        if (car && car == R1[zero + 1]) {
          ans.push_back(make_tuple(car, 1, zero + 1));
          k--;
        } else if (car && car == R1[zero]) {
          ans.push_back(make_tuple(car, 2, zero));
          ans.push_back(make_tuple(car, 1, zero));
          k--;
        } else if (car) {
          A[zero] = car;
          ans.push_back(make_tuple(car, 2, zero));
        }
        zero++;
        A[zero] = 0;
      }
    }
    while (row == 3 && k) {
      if (zero == 1) {
        int car = A[1];
        if (car && car == R1[1]) {
          ans.push_back(make_tuple(car, 1, 1));
          k--;
        } else if (car && car == R2[1]) {
          ans.push_back(make_tuple(car, 3, 1));
          ans.push_back(make_tuple(car, 4, 1));
          k--;
        } else if (car) {
          ans.push_back(make_tuple(car, 3, 1));
          B[1] = car;
        }
        A[1] = 0;
        row = 2;
      } else {
        int car = B[zero - 1];
        if (car && car == R2[zero - 1]) {
          ans.push_back(make_tuple(car, 4, zero - 1));
          k--;
        } else if (car && car == R2[zero]) {
          ans.push_back(make_tuple(car, 3, zero));
          ans.push_back(make_tuple(car, 4, zero));
          k--;
        } else if (car) {
          ans.push_back(make_tuple(car, 3, zero));
          B[zero] = car;
        }
        zero--;
        B[zero] = 0;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i])
         << endl;
  }
}
