#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int INF = 1 << 30;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
struct num {
  int a, x, y;
};
long long n, k, a[55][7];
queue<num> q;
void swap(int x1, int y1, int x2, int y2) {
  if (a[x1][y1] == 0 && a[x2][y2] == 0) return;
  if (a[x1][y1] == 0) swap(x1, x2), swap(y1, y2);
  num t;
  t.a = a[x1][y1], t.x = x2, t.y = y2;
  q.push(t);
  a[x1][y1] = a[x2][y2];
  a[x2][y2] = t.a;
}
void judg(int i) {
  if (a[i][2] != 0 && a[i][2] == a[i][1]) {
    num t;
    t.a = a[i][2];
    a[i][2] = 0;
    t.x = i, t.y = 1;
    q.push(t);
  }
  if (a[i][3] != 0 && a[i][3] == a[i][4]) {
    num t;
    t.a = a[i][3];
    a[i][3] = 0;
    t.x = i, t.y = 4;
    q.push(t);
  }
}
int main() {
  cin >> n >> k;
  for (int j = 1; j <= 4; j++)
    for (int i = 1; i <= n; i++) cin >> a[i][j];
  {
    for (int i = 1; i <= n; i++) {
      judg(i);
    }
    if (n * 2 == k && q.empty()) {
      cout << -1 << endl;
      return 0;
    }
  }
  int mx = 0, my, tol = 2 * n;
  for (int J = 2; J <= 3; J++)
    if (mx == 0)
      for (int I = 1; I <= n; I++) {
        if (a[I][J] == 0) {
          mx = I, my = J;
          break;
        }
      }
  if (my == 3) swap(mx, 3, mx, 2), my = 2;
  while (tol--) {
    for (int i = mx + 1; i <= n; i++) swap(mx++, my, i, my);
    swap(mx, my++, mx, my);
    for (int i = n - 1; i >= 1; i--) swap(mx--, my, i, my);
    for (int i = 1; i <= n; i++) {
      judg(i);
    }
    swap(mx, my--, mx, my);
    for (int i = 2; i <= mx; i++) swap(mx++, my, i, my);
    for (int i = 1; i <= n; i++) {
      judg(i);
    }
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    num t = q.front();
    q.pop();
    cout << t.a << " " << t.y << " " << t.x << endl;
  }
}
