#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  long long n, k, a, b, c, d, e, f, i, j;
  cin >> n >> k;
  long long x[6][n + 5];
  for (i = 1; i <= 4; i++) {
    for (j = 1; j <= n; j++) {
      cin >> x[i][j];
    }
  }
  if (k == 2 * n) {
    c = 0;
    for (i = 1; i <= n; i++) {
      if (x[1][i] == x[2][i]) c = 1;
      if (x[3][i] == x[4][i]) c = 1;
    }
    if (c == 0) {
      cout << "-1";
      return 0;
    }
  }
  long long to = k;
  long long it = 0;
  vector<pair<long long, pair<long long, long long> > > ans;
  while (to > 0) {
    for (i = 1; i <= n; i++) {
      if (x[1][i] == x[2][i] && x[1][i] != 0) {
        ans.push_back({x[1][i], {1, i}});
        x[2][i] = 0;
        to--;
      }
      if (x[3][i] == x[4][i] && x[3][i] != 0) {
        ans.push_back({x[3][i], {4, i}});
        x[3][i] = 0;
        to--;
      }
    }
    if (to == 0) break;
    long long x1, y1;
    long long x2, y2, x3, y3;
    for (i = 1; i <= n; i++) {
      if (x[2][i] == 0) {
        x1 = 2;
        y1 = i;
        break;
      }
      if (x[3][i] == 0) {
        x1 = 3;
        y1 = i;
        break;
      }
    }
    x3 = x1;
    y3 = y1;
    while (true) {
      if (x1 == 2) {
        if (y1 == n) {
          x2 = 3;
          y2 = n;
        } else {
          x2 = 2;
          y2 = y1 + 1;
        }
      } else {
        if (y1 == 1) {
          x2 = 2;
          y2 = 1;
        } else {
          x2 = 3;
          y2 = y1 - 1;
        }
      }
      if ((x2 == x3) && (y2 == y3)) break;
      if (x[x2][y2] != 0) {
        ans.push_back({x[x2][y2], {x1, y1}});
        x[x1][y1] = x[x2][y2];
        x[x2][y2] = 0;
      }
      x1 = x2;
      y1 = y2;
    }
  }
  cout << ans.size() << "\n";
  for (auto z : ans) {
    cout << z.first << " " << z.second.first << " " << z.second.second << "\n";
  }
  return 0;
}
