#include <bits/stdc++.h>
using namespace std;
int N, K;
int arr[5][59];
queue<pair<int, int>> q;
vector<pair<int, pair<int, int>>> vs;
void init() {
  cin >> N >> K;
  for (int i = 1; i <= 4; ++i)
    for (int j = 1; j <= N; ++j) cin >> arr[i][j];
  for (int j = 1; j <= N; ++j)
    if (arr[2][j]) q.push({2, j});
  for (int j = N; j >= 1; --j)
    if (arr[3][j]) q.push({3, j});
}
void rotate() {
  for (int i = 0; i < q.size(); ++i) {
    int y = q.front().first;
    int x = q.front().second;
    if (y == 2)
      x == 1 ? ++y : --x;
    else
      x == N ? --y : ++x;
    if (arr[y][x] == 0) break;
    q.push(q.front());
    q.pop();
  }
  for (int i = 0; i < q.size(); ++i) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    int ny = y, nx = x;
    if (y == 2)
      x == 1 ? ++ny : --nx;
    else
      x == N ? --ny : ++nx;
    q.push({ny, nx});
    vs.push_back({arr[y][x], {ny, nx}});
    arr[ny][nx] = arr[y][x];
    arr[y][x] = 0;
  }
}
bool match() {
  bool ret = false;
  int size = q.size();
  for (int i = 0; i < size; ++i) {
    int y = q.front().first;
    int x = q.front().second;
    if (y == 2) {
      if (arr[y][x] == arr[1][x]) {
        vs.push_back({arr[y][x], {1, x}});
        ret = true;
        arr[y][x] = 0;
      } else
        q.push(q.front());
    } else {
      if (arr[y][x] == arr[4][x]) {
        vs.push_back({arr[y][x], {4, x}});
        ret = true;
        arr[y][x] = 0;
      } else
        q.push(q.front());
    }
    q.pop();
  }
  return ret;
}
void solve() {
  if (!match() && K == 2 * N) {
    puts("-1");
    return;
  }
  while (!q.empty()) {
    rotate();
    match();
  }
  printf("%d\n", vs.size());
  for (int i = 0; i < vs.size(); ++i)
    printf("%d %d %d\n", vs[i].first, vs[i].second.first, vs[i].second.second);
}
int main(int argc, char** argv) {
  int t = 1;
  for (int i = 0; i < t; ++i) {
    init();
    solve();
  }
  return 0;
}
