#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 55;
int a[N][N], b[N][N], n, k;
struct step {
  int i, x, y;
};
vector<step> ans;
void move() {
  vector<step> cur;
  for (int i = 2; i <= 3; i++) {
    if (i == 2)
      for (int j = 1; j <= n; j++) {
        if (i == 2 && j < n)
          b[i][j] = a[i][j + 1], b[i][j] ? cur.push_back({b[i][j], i, j}),
          1 : 0;
        if (i == 2 && j == n)
          b[i][j] = a[i + 1][j], b[i][j] ? cur.push_back({b[i][j], i, j}),
          1 : 0;
      }
    else
      for (int j = n; j; j--) {
        if (i == 3 && j > 1)
          b[i][j] = a[i][j - 1], b[i][j] ? cur.push_back({b[i][j], i, j}),
          1 : 0;
        if (i == 3 && j == 1)
          b[i][j] = a[i - 1][j], b[i][j] ? cur.push_back({b[i][j], i, j}),
          1 : 0;
      }
  }
  int pos;
  for (int i = 0; i < cur.size(); i++)
    if (!a[cur[i].x][cur[i].y]) {
      pos = i;
      break;
    }
  for (int i = 0; i < cur.size(); i++)
    ans.push_back(cur[(pos + i) % cur.size()]);
  for (int i = 2; i <= 3; i++)
    for (int j = 1; j <= n; j++) a[i][j] = b[i][j];
}
int erase() {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[2][i] && a[1][i] == a[2][i])
      ans.push_back({a[1][i], 1, i}), a[1][i] = a[2][i] = 0, cnt++;
    if (a[3][i] && a[3][i] == a[4][i])
      ans.push_back({a[4][i], 4, i}), a[4][i] = a[3][i] = 0, cnt++;
  }
  return cnt;
}
signed main() {
  read(n, k);
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) read(a[i][j]);
  k -= erase();
  if (k == 2 * n) return write(-1), 0;
  while (k) {
    move();
    k -= erase();
  }
  write(ans.size());
  puts("");
  for (auto x : ans) printf("%d %d %d\n", x.i, x.x, x.y);
}
