#include <bits/stdc++.h>
using ::std::cin;
using ::std::cout;
using ::std::endl;
using ::std::swap;
using ::std::tuple;
using ::std::vector;
int main() {
  ::std::ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> cars(2 * n), spaces(2 * n);
  for (int i = 0; i < n; ++i) cin >> spaces[i];
  for (int i = 0; i < n; ++i) cin >> cars[i];
  for (int i = 2 * n - 1; i >= n; --i) cin >> cars[i];
  for (int i = 2 * n - 1; i >= n; --i) cin >> spaces[i];
  vector<tuple<int, int, int>> solution;
  for (int i = 0; i < 2 * n; ++i)
    if (cars[i] != 0 && cars[i] == spaces[i]) {
      solution.push_back(
          {cars[i], (i < n ? 1 : 4), (i < n ? 1 + i : 2 * n - i)});
      cars[i] = 0;
      --k;
    }
  while (k) {
    int emptyNext = 0;
    while (emptyNext < 2 * n && (cars[emptyNext] != 0 ||
                                 cars[(2 * n + emptyNext - 1) % (2 * n)] == 0))
      ++emptyNext;
    if (emptyNext == 2 * n) {
      cout << -1 << endl;
      return 0;
    }
    int nonemptyPrevious = (2 * n + emptyNext - 1) % (2 * n);
    solution.push_back({
        cars[nonemptyPrevious],
        (emptyNext < n ? 2 : 3),
        (emptyNext < n ? 1 + emptyNext : 2 * n - emptyNext),
    });
    swap(cars[nonemptyPrevious], cars[emptyNext]);
    if (cars[emptyNext] == spaces[emptyNext]) {
      solution.push_back({
          cars[emptyNext],
          (emptyNext < n ? 1 : 4),
          (emptyNext < n ? 1 + emptyNext : 2 * n - emptyNext),
      });
      cars[emptyNext] = 0;
      --k;
    }
  }
  cout << solution.size() << "\n";
  for (auto [i, r, c] : solution) cout << i << " " << r << " " << c << "\n";
  return 0;
}
