#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k, mas[10005][4], aa, ab[20005], rez[3][400005], r, bb;
int main() {
  cin >> n >> m;
  j = 0;
  while (j < 4) {
    i = 0;
    while (i < n) {
      cin >> mas[i][j];
      i++;
    }
    j++;
  }
  if (m == 2 * n) {
    i = 0;
    aa = 0;
    while (i < n) {
      if (mas[i][0] == mas[i][1]) {
        rez[0][r] = mas[i][1];
        rez[1][r] = 1;
        rez[2][r] = i;
        r++;
        mas[i][1] = 0;
        m--;
        aa = 1;
      }
      if (mas[i][2] == mas[i][3]) {
        rez[0][r] = mas[i][2];
        rez[1][r] = 4;
        rez[2][r] = i;
        r++;
        mas[i][2] = 0;
        m--;
        aa = 1;
      }
      i++;
    }
    if (aa == 0) {
      cout << "-1";
      return 0;
    }
  }
  i = 0;
  while (i < n) {
    if (mas[i][1] == 0) {
      j = i;
    }
    i++;
  }
  i = n - 1;
  k = n;
  while (i >= 0) {
    if (mas[i][2] == 0) {
      j = k;
    }
    k++;
    i--;
  }
  i = 0;
  while (i < n) {
    ab[i] = mas[i][1];
    i++;
  }
  i = n - 1;
  k = 0;
  while (i >= 0) {
    ab[k + n] = mas[i][2];
    i--;
    k++;
  }
  aa = 0;
  bb = -1;
  while (m > 0) {
    i = j;
    k = 0;
    while (k < 2 * n) {
      if (ab[(i + 1) % (2 * n)] != 0) {
        if ((i + 1) % (2 * n) < n &&
            mas[(i + 1) % (2 * n)][0] == ab[(i + 1) % (2 * n)]) {
          rez[0][r] = ab[(i + 1) % (2 * n)];
          rez[1][r] = 1;
          rez[2][r] = (i + 1) % (2 * n);
          r++;
          m--;
          ab[(i + 1) % (2 * n)] = 0;
        } else if ((i + 1) % (2 * n) >= n &&
                   mas[2 * n - (i + 1) % (2 * n) - 1][3] ==
                       ab[(i + 1) % (2 * n)]) {
          rez[0][r] = ab[(i + 1) % (2 * n)];
          rez[1][r] = 4;
          rez[2][r] = 2 * n - (i + 1) % (2 * n) - 1;
          r++;
          m--;
          ab[(i + 1) % (2 * n)] = 0;
        } else {
          rez[0][r] = ab[(i + 1) % (2 * n)];
          if ((i) % (2 * n) < n) {
            rez[1][r] = 2;
            rez[2][r] = (i) % (2 * n);
          } else {
            rez[1][r] = 3;
            rez[2][r] = 2 * n - (i) % (2 * n) - 1;
          }
          ab[(i) % (2 * n)] = ab[(i + 1) % (2 * n)];
          ab[(i + 1) % (2 * n)] = 0;
          r++;
        }
      }
      i++;
      k++;
    }
  }
  cout << r << "\n";
  i = 0;
  while (i < r) {
    cout << rez[0][i] << " " << rez[1][i] << " " << rez[2][i] + 1 << "\n";
    i++;
  }
  return 0;
}
