#include <bits/stdc++.h>
using namespace std;
int N, K;
int mat[4][50];
int moves = 0;
stringstream s;
void lookCars() {
  for (int i = 0; i < N; i++) {
    if (mat[1][i] == mat[0][i] && mat[1][i]) {
      mat[1][i] = 0;
      K--;
      moves++;
      s << mat[0][i] << " 1 " << i + 1 << "\n";
    }
    if (mat[3][i] == mat[2][i] && mat[3][i]) {
      mat[2][i] = 0;
      K--;
      moves++;
      s << mat[3][i] << " 4 " << i + 1 << "\n";
    }
  }
}
void move(int car, int ind) {
  if (ind < N) {
    moves++;
    s << car << " " << 2 << " " << (ind + 1) << "\n";
  } else {
    moves++;
    int x = (N - (ind - N));
    s << car << " " << 3 << " " << x << "\n";
  }
}
int strip[100];
void rotateCars() {
  for (int i = 0; i < N; i++) strip[i] = mat[1][i];
  for (int i = 0; i < N; i++) strip[N + i] = mat[2][N - 1 - i];
  int ind = 0;
  while (strip[ind]) ind++;
  int car = strip[ind];
  for (int i = 1; i < 2 * N; i++) {
    int ni = (ind + i) % (2 * N);
    int nj = (ni - 1 + 2 * N) % (2 * N);
    if (strip[ni]) {
      move(strip[ni], nj);
    }
    strip[nj] = strip[ni];
  }
  int nnn = (ind - 1 + 2 * N) % (2 * N);
  if (car) {
    move(car, nnn);
  }
  strip[nnn] = car;
  for (int i = 0; i < N; i++) mat[1][i] = strip[i];
  for (int i = 0; i < N; i++) mat[2][N - 1 - i] = strip[N + i];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int d = 0; d < 4; d++) {
    for (int i = 0; i < N; i++) {
      cin >> mat[d][i];
    }
  }
  if (K == 2 * N) {
    lookCars();
    if (K == 2 * N) {
      cout << -1;
      return 0;
    }
  }
  while (K) {
    lookCars();
    rotateCars();
  }
  cout << moves << "\n";
  cout << s.str();
  return 0;
}
