#include <bits/stdc++.h>
using namespace std;
int n, k;
int P[4][50];
vector<pair<int, pair<int, int> > > moves;
void meter() {
  for (int i = 0; i < n; i++) {
    if (P[2][i] == P[3][i]) {
      if (P[2][i] != 0)
        moves.push_back(make_pair(P[2][i], make_pair(4, i + 1)));
      P[2][i] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (P[1][i] == P[0][i]) {
      if (P[1][i] != 0)
        moves.push_back(make_pair(P[1][i], make_pair(1, i + 1)));
      P[1][i] = 0;
    }
  }
  return;
}
int mem[200];
void girar() {
  int start = 0;
  if ((P[2][0] != 0) && (P[1][0] == 0) && (mem[P[2][0]] == 0)) {
    moves.push_back(make_pair(P[2][0], make_pair(2, 1)));
    P[1][0] = P[2][0];
    mem[P[2][0]] = 1;
    P[2][0] = 0;
    start++;
  }
  for (int i = start; i < n - 1; i++) {
    if ((P[1][i] != 0) && (P[1][i + 1] == 0) && (mem[P[1][i]] == 0)) {
      moves.push_back(make_pair(P[1][i], make_pair(2, i + 2)));
      P[1][i + 1] = P[1][i];
      mem[P[1][i]] = 1;
      P[1][i] = 0;
      i++;
    }
  }
  start = n - 1;
  if ((P[1][n - 1] != 0) && (P[2][n - 1] == 0) && (mem[P[1][n - 1]] == 0)) {
    moves.push_back(make_pair(P[1][n - 1], make_pair(3, n)));
    P[2][n - 1] = P[1][n - 1];
    mem[P[1][n - 1]] = 1;
    P[1][n - 1] = 0;
    start--;
  }
  for (int i = start; i > 0; i--) {
    if ((P[2][i] != 0) && (P[2][i - 1] == 0) && (mem[P[2][i - 1]] == 0)) {
      moves.push_back(make_pair(P[2][i], make_pair(3, i)));
      mem[P[2][i]] = 1;
      P[2][i - 1] = P[2][i];
      P[2][i] = 0;
      i--;
    }
  }
  return;
}
int verify() {
  int zeros = 0;
  for (int i = 0; i < n; i++) {
    zeros += (P[1][i] == 0);
    zeros += (P[2][i] == 0);
  }
  return zeros;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &P[i][j]);
    }
  }
  meter();
  int salir;
  k = k * 2;
  while (moves.size() <= 20000) {
    salir = verify();
    if (salir == 2 * n) {
      printf("%d\n", (int)moves.size());
      for (int i = 0; i < (int)moves.size(); i++) {
        printf("%d %d %d\n", moves[i].first, moves[i].second.first,
               moves[i].second.second);
      }
      return 0;
    }
    for (int i = 0; i < 2 * (n + 1); i++) mem[i] = 0;
    k--;
    girar();
    meter();
    if (moves.size() == 0) {
      printf("-1\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
