#include <bits/stdc++.h>
using namespace std;
int a[5][60];
int b[5][60];
int main() {
  int n, K, k, ans = 0;
  cin >> n >> K;
  k = K;
  for (int j = 1; j <= 4; j++)
    for (int i = 1; i <= n; i++) cin >> b[j][i];
  for (int j = 1; j <= 4; j++)
    for (int i = 1; i <= n; i++) a[j][i] = b[j][i];
  if (k == 2 * n) {
    bool cant = 1;
    for (int i = 1; i <= n; i++)
      if (a[1][i] == a[2][i]) cant = 0;
    for (int i = 1; i <= n; i++)
      if (a[3][i] == a[4][i]) cant = 0;
    if (cant) return puts("-1"), 0;
  }
  while (k) {
    for (int i = 1; i <= n; i++)
      if (a[2][i]) {
        if (a[1][i] == a[2][i]) {
          a[2][i] = 0, ans++, k--;
          continue;
        }
        if (i == n) {
          if (a[3][i] == 0) ans++, a[3][i] = a[2][i], a[2][i] = 0;
        } else if (a[2][i + 1] == 0) {
          ans++, a[2][i + 1] = a[2][i], a[2][i] = 0;
        }
      }
    for (int i = n; i >= 1; i--)
      if (a[3][i]) {
        if (a[4][i] == a[3][i]) {
          a[3][i] = 0, ans++, k--;
          continue;
        }
        if (i == 1) {
          if (a[2][i] == 0) ans++, a[2][i] = a[3][i], a[3][i] = 0;
        } else if (a[3][i - 1] == 0) {
          ans++, a[3][i - 1] = a[3][i], a[3][i] = 0;
        }
      }
  }
  for (int j = 1; j <= 4; j++)
    for (int i = 1; i <= n; i++) a[j][i] = b[j][i];
  k = K;
  cout << ans << endl;
  while (k) {
    for (int i = 1; i <= n; i++)
      if (a[2][i]) {
        if (a[1][i] == a[2][i]) {
          a[2][i] = 0, printf("%d %d %d\n", a[1][i], 1, i), k--;
          continue;
        }
        if (i == n) {
          if (a[3][i] == 0)
            printf("%d %d %d\n", a[2][i], 3, i), a[3][i] = a[2][i], a[2][i] = 0;
        } else if (a[2][i + 1] == 0) {
          printf("%d %d %d\n", a[2][i], 2, i + 1), a[2][i + 1] = a[2][i],
                                                            a[2][i] = 0;
        }
      }
    for (int i = n; i >= 1; i--)
      if (a[3][i]) {
        if (a[4][i] == a[3][i]) {
          a[3][i] = 0, printf("%d %d %d\n", a[4][i], 4, i), k--;
          continue;
        }
        if (i == 1) {
          if (a[2][i] == 0)
            printf("%d %d %d\n", a[3][i], 2, i), a[2][i] = a[3][i], a[3][i] = 0;
        } else if (a[3][i - 1] == 0) {
          printf("%d %d %d\n", a[3][i], 3, i - 1), a[3][i - 1] = a[3][i],
                                                            a[3][i] = 0;
        }
      }
  }
  return 0;
}
