#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n, k, a[5][52];
vector<tuple<int, int, int>> ans;
void roundRobin() {
  vector<pii> pos;
  for (int i = 1; i <= n; i++) pos.emplace_back(2, i);
  for (int i = n; i >= 1; i--) pos.emplace_back(3, i);
  int si = 0;
  while (a[pos[si].first][pos[si].second] > 0) si++;
  int index = si;
  do {
    int ci = pos[index].first;
    int ti = ci == 2 ? 1 : 4;
    int cj = pos[index].second;
    int ni = pos[(index + 1) % pos.size()].first;
    int nj = pos[(index + 1) % pos.size()].second;
    if (a[ni][nj] > 0) {
      ans.emplace_back(a[ni][nj], ci, cj);
      a[ci][cj] = a[ni][nj];
      a[ni][nj] = 0;
      if (a[ci][cj] == a[ti][cj]) {
        k--;
        ans.emplace_back(a[ti][cj], ti, cj);
        a[ci][cj] = a[ti][cj] = 0;
      }
    }
    index = (index + 1) % pos.size();
  } while (index != si);
}
void trivial() {
  for (int i = 1; i <= n; i++) {
    if (a[1][i] > 0 && a[1][i] == a[2][i]) {
      k--;
      ans.emplace_back(a[1][i], 1, i);
      a[1][i] = a[2][i] = 0;
    }
    if (a[4][i] > 0 && a[4][i] == a[3][i]) {
      k--;
      ans.emplace_back(a[4][i], 4, i);
      a[4][i] = a[3][i] = 0;
    }
  }
  if (k == 2 * n) {
    cout << "-1\n";
    exit(0);
  }
  while (k > 0) roundRobin();
  cout << ans.size() << endl;
  for (const auto& x : ans) {
    cout << get<0>(x) << " " << get<1>(x) << " " << get<2>(x) << endl;
  }
}
void solve() { trivial(); }
void load() {
  cin >> n >> k;
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  load();
  solve();
  return 0;
}
