#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3F3F3F3F;
const int MOD = 1e9 + 7;
const int MAX = 55;
int N, K;
int arr[5][MAX];
vector<pair<int, pair<int, int> > > ans;
inline void move(pair<int, int> rc, pair<int, int> rc1) {
  int r = rc.first, c = rc.second, r1 = rc1.first, c1 = rc1.second;
  if (arr[r][c] != 0 && (arr[r1][c1] == 0 || arr[r1][c1] == arr[r][c])) {
    ans.push_back({arr[r][c], {r1, c1}});
    arr[r1][c1] = arr[r][c];
    arr[r][c] = 0;
  }
}
inline int park() {
  int ret = 0;
  for (int i = 1; i <= N; i++) {
    move({2, i}, {1, i});
    move({3, i}, {4, i});
  }
  for (int i = 1; i <= N; i++) {
    ret += arr[2][i] != 0;
    ret += arr[3][i] != 0;
  }
  return ret;
}
inline pair<int, int> prev(pair<int, int> rc) {
  int r = rc.first, c = rc.second;
  if (r == 2) {
    if (c == 1) {
      return {3, 1};
    } else {
      return {r, c - 1};
    }
  } else {
    if (c == N) {
      return {2, N};
    } else {
      return {r, c + 1};
    }
  }
}
inline pair<int, int> next(pair<int, int> rc) {
  int r = rc.first, c = rc.second;
  if (r == 2) {
    if (c == N) {
      return {3, N};
    } else {
      return {r, c + 1};
    }
  } else {
    if (c == 1) {
      return {2, 1};
    } else {
      return {r, c - 1};
    }
  }
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= N; j++) {
      scanf("%d", &arr[i][j]);
      if ((i == 1 || i == 4) && arr[i][j] == 0) {
        arr[i][j] = -1;
      }
    }
  }
  if (K == 2 * N && park() == K) {
    printf("-1\n");
    return 0;
  }
  while (park()) {
    pair<int, int> rc = {2, 1};
    while (arr[next(rc).first][next(rc).second] != 0) {
      rc = next(rc);
    }
    int cnt = 0;
    while (cnt < 2 * N - 1) {
      move(rc, next(rc));
      rc = prev(rc);
      cnt++;
    }
  }
  printf("%d\n", (int)ans.size());
  for (pair<int, pair<int, int> > p : ans) {
    printf("%d %d %d\n", p.first, p.second.first, p.second.second);
  }
  return 0;
}
