#include <bits/stdc++.h>
using namespace std;
long long int n, k, a[5][59], b[5], cnt = 0;
pair<long long int, long long int> nex[5][59], af[5][59];
struct T {
  long long int first, second, z;
};
deque<T> kq;
void Inp() {
  cin >> n >> k;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  b[2] = 1;
  b[3] = 4;
  for (int i = 1; i <= n; i++) {
    nex[2][i] = make_pair(2, i + 1);
    nex[3][i] = make_pair(3, i - 1);
    af[2][i] = make_pair(2, i - 1);
    af[3][i] = make_pair(3, i + 1);
  }
  nex[2][n] = make_pair(3, n);
  nex[3][1] = make_pair(2, 1);
  af[2][1] = make_pair(3, 1);
  af[3][n] = make_pair(2, n);
}
void quay() {
  pair<long long int, long long int> p, p1, p2;
  bool ok = 0;
  for (int i = 2; i <= 3; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == 0) {
        p = make_pair(i, j);
        ok = 1;
        break;
      }
    }
    if (ok) {
      break;
    }
  }
  p1 = af[p.first][p.second];
  while (p1 != p) {
    p2 = nex[p1.first][p1.second];
    if (a[p1.first][p1.second] > 0) {
      kq.push_back({a[p1.first][p1.second], p2.first, p2.second});
    }
    a[p2.first][p2.second] = a[p1.first][p1.second];
    p1 = af[p1.first][p1.second];
  }
  a[nex[p.first][p.second].first][nex[p.first][p.second].second] = 0;
}
void Out() {
  cout << kq.size() << endl;
  for (auto v : kq) {
    cout << v.first << " " << v.second << " " << v.z << endl;
  }
}
void Solve() {
  while (k > 0) {
    for (int i = 2; i <= 3; i++) {
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == a[b[i]][j] && a[i][j] > 0) {
          kq.push_back({a[i][j], b[i], j});
          k--;
          a[i][j] = 0;
          a[b[i]][j] = 0;
        }
      }
    }
    if (k == 2 * n) {
      cout << -1;
      return;
    }
    quay();
  }
  Out();
}
int main() {
  Inp();
  Solve();
}
