#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
int n, k;
int s[5][maxn], ss = 0, cnt = 0;
struct ANS {
  int a, b, c;
} ans[500007];
void print(int a, int b, int c) {
  cnt++;
  ans[cnt].a = a;
  ans[cnt].b = b;
  ans[cnt].c = c;
}
void OUT() {
  for (int i = 2; i <= 4; i += 2) {
    for (int j = 1; j <= n; j++) {
      if (s[i][j] == s[i - 1][j] && s[i][j] != 0) {
        if (i == 2)
          print(s[i][j], i - 1, j);
        else
          print(s[i][j], i, j);
        s[i][j] = s[i - 1][j] = 0;
        ss++;
      }
    }
  }
}
int MOVE() {
  int st = 0, oo = 0;
  for (int i = 1; i <= n; i++) {
    if (s[2][i] == 0) {
      st = i + 1;
      oo = 2;
      break;
    }
  }
  if (!st) {
    for (int i = 1; i <= n; i++) {
      if (s[4][i] == 0) {
        st = i - 1;
        oo = 4;
        break;
      }
    }
  }
  if (st == 0 && oo == 0) return 0;
  if (st == 0 && oo == 4) {
    if (s[2][1]) {
      print(s[2][1], 3, 1);
      swap(s[2][1], s[4][1]);
    }
    for (int i = 2; i <= n; i++) {
      if (s[2][i]) print(s[2][i], 2, i - 1), swap(s[2][i], s[2][i - 1]);
    }
    if (n != st + 1 && s[4][n]) {
      print(s[4][n], 2, n);
      swap(s[4][n], s[2][n]);
    }
    for (int i = n - 1; i >= 2; i--) {
      if (s[4][i]) print(s[4][i], 3, i + 1), swap(s[4][i], s[4][i + 1]);
    }
    return 1;
  }
  if (st == n + 1 && oo == 2) {
    if (s[4][n]) {
      print(s[4][n], 2, n);
      swap(s[4][n], s[2][n]);
    }
    for (int i = n - 1; i >= 1; i--) {
      if (s[4][i]) print(s[4][i], 3, i + 1), swap(s[4][i], s[4][i + 1]);
    }
    if (1 != st - 1 && s[2][1]) {
      print(s[2][1], 3, 1);
      swap(s[2][1], s[4][1]);
    }
    for (int i = 2; i < n; i++) {
      if (s[2][i]) print(s[2][i], 2, i - 1), swap(s[2][i], s[2][i - 1]);
    }
    return 1;
  }
  if (oo == 2) {
    for (int i = st; i <= n; i++) {
      if (s[2][i]) print(s[2][i], 2, i - 1), swap(s[2][i], s[2][i - 1]);
    }
    if (s[4][n]) {
      print(s[4][n], 2, n);
      swap(s[4][n], s[2][n]);
    }
    for (int i = n - 1; i >= 1; i--) {
      if (s[4][i]) print(s[4][i], 3, i + 1), swap(s[4][i], s[4][i + 1]);
    }
    if (st != 2 && s[2][1]) {
      print(s[2][1], 3, 1);
      swap(s[2][1], s[4][1]);
    }
    for (int i = 2; i < st - 1; i++) {
      if (s[2][i]) print(s[2][i], 2, i - 1), swap(s[2][i], s[2][i - 1]);
    }
  } else {
    for (int i = st; i >= 1; i--) {
      if (s[4][i]) print(s[4][i], 3, i + 1), swap(s[4][i], s[4][i + 1]);
    }
    if (s[2][1]) {
      print(s[2][1], 3, 1);
      swap(s[2][1], s[4][1]);
    }
    for (int i = 2; i <= n; i++) {
      if (s[2][i]) print(s[2][i], 2, i - 1), swap(s[2][i], s[2][i - 1]);
    }
    if (st != n - 1 && s[4][n]) {
      print(s[4][n], 2, n);
      swap(s[4][n], s[2][n]);
    }
    for (int i = n - 1; i > st + 1; i--) {
      if (s[4][i]) print(s[4][i], 3, i + 1), swap(s[4][i], s[4][i + 1]);
    }
  }
  return 1;
}
void work() {
  int tt = 0;
  while (ss < k) {
    OUT();
    if (MOVE())
      ;
    else {
      printf("-1\n");
      return;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++)
    printf("%d %d %d\n", ans[i].a, ans[i].b, ans[i].c);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) swap(s[3][i], s[4][i]);
  work();
  return 0;
}
