#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
const long long MOD = 1e9 + 7;
int N, K;
vector<vector<int>> res;
int g[6][55];
inline void move(int r1, int c1, int r2, int c2) {
  g[r2][c2] = g[r1][c1];
  g[r1][c1] = 0;
  res.push_back({g[r2][c2], r2, c2});
}
inline void nxt(int& r, int& c) {
  c = (r == 2 ? c + 1 : c - 1);
  if (c > N)
    c = N, r = 3;
  else if (c < 1)
    c = 1, r = 2;
}
inline bool rot() {
  int r0, c0;
  bool good = 0;
  for (int i = 2; i <= 3; i++) {
    if (good) break;
    for (int j = 1; j <= N; j++) {
      if (g[i][j] == 0) {
        good = 1;
        r0 = i, c0 = j;
        break;
      }
    }
  }
  if (!good) return 0;
  int r = r0, c = c0;
  int r1 = r, c1 = c;
  nxt(r1, c1);
  while (!(r1 == r0 && c1 == c0)) {
    if (g[r1][c1] != 0) {
      move(r1, c1, r, c);
    }
    nxt(r, c);
    nxt(r1, c1);
  }
  return 1;
}
inline bool slot() {
  bool good = 0;
  for (int j = 1; j <= N; j++) {
    if (g[2][j] == 0) continue;
    if (g[1][j] == g[2][j]) {
      good = 1;
      move(2, j, 1, j);
      K--;
    }
  }
  for (int j = 1; j <= N; j++) {
    if (g[3][j] == 0) continue;
    if (g[4][j] == g[3][j]) {
      good = 1;
      move(3, j, 4, j);
      K--;
    }
  }
  return good;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> g[i][j];
    }
  }
  if (2 * N == K) {
    bool good = slot();
    if (!good) {
      cout << "-1\n";
      return 0;
    }
  }
  while (K > 0) {
    slot();
    rot();
  }
  cout << res.size() << '\n';
  for (auto& v : res) {
    cout << v[0] << ' ' << v[1] << ' ' << v[2] << '\n';
  }
  return 0;
}
