#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int board[4][n];
  for (int i = 0; i < (4); i++) {
    for (int j = 0; j < (n); j++) {
      scanf("%d", &board[i][j]);
      board[i][j]--;
    }
  }
  vector<pair<int, pair<int, int>>> moves;
  bool flag = true;
  while (flag && k > 0) {
    flag = false;
    for (int i = 0; i < (n); i++) {
      if (board[0][i] != -1 && board[0][i] == board[1][i]) {
        moves.push_back({board[0][i] + 1, {1, i + 1}});
        board[1][i] = -1;
        k--;
        flag = true;
      }
      if (board[3][i] != -1 && board[3][i] == board[2][i]) {
        moves.push_back({board[3][i] + 1, {4, i + 1}});
        board[2][i] = -1;
        k--;
        flag = true;
      }
    }
    if (board[1][0] == -1 && board[2][0] != -1) {
      moves.push_back({board[2][0] + 1, {2, 1}});
      board[1][0] = board[2][0];
      board[2][0] = -1;
      flag = true;
    } else {
      for (int i = 1; i < (n); i++) {
        if (board[1][i - 1] != -1 && board[1][i] == -1) {
          moves.push_back({board[1][i - 1] + 1, {2, i + 1}});
          board[1][i] = board[1][i - 1];
          board[1][i - 1] = -1;
          flag = true;
          break;
        }
      }
      if (!flag) {
        if (board[1][n - 1] != -1 && board[2][n - 1] == -1) {
          moves.push_back({board[1][n - 1] + 1, {3, n}});
          board[2][n - 1] = board[1][n - 1];
          board[1][n - 1] = -1;
          flag = true;
        } else {
          for (int i = n - 2; i >= 0; i--) {
            if (board[2][i + 1] != -1 && board[2][i] == -1) {
              moves.push_back({board[2][i + 1] + 1, {3, i + 1}});
              board[2][i] = board[2][i + 1];
              board[2][i + 1] = -1;
              flag = true;
              break;
            }
          }
        }
      }
    }
  }
  if (k > 0)
    printf("%d\n", -1);
  else {
    printf("%d\n", (int)moves.size());
    for (pair<int, pair<int, int>> pp : moves) {
      printf("%d %d %d\n", pp.first, pp.second.first, pp.second.second);
    }
  }
  return 0;
}
