#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[8][128];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= 4; ++i)
    for (int j = 1; j <= n; ++j) cin >> a[i][j];
  vector<tuple<int, int, int>> ans;
  if (k == 2 * n) {
    for (int i = 1; i <= n; ++i) {
      if (a[1][i] == a[2][i]) {
        ans.emplace_back(a[1][i], 1, i);
        a[2][i] = 0;
        k--;
      }
      if (a[4][i] == a[3][i]) {
        ans.emplace_back(a[4][i], 4, i);
        a[3][i] = 0;
        k--;
      }
      if (a[2][i] == 0 || a[3][i] == 0) break;
    }
    if (ans.empty()) return cout << -1, 0;
  }
  vector<pair<int, int>> loop;
  loop.reserve(512);
  for (int i = 1; i <= n; ++i) loop.emplace_back(2, i);
  for (int i = n; i >= 1; --i) loop.emplace_back(3, i);
  int m = loop.size();
  for (int i = 0; k > 0; i = (i + 1) % m) {
    int next = (i + 1) % m;
    auto [x1, y1] = loop[i];
    auto [x2, y2] = loop[next];
    int o = (x2 == 2 ? 1 : 4);
    if (a[o][y2] && a[x2][y2] == a[o][y2]) {
      ans.emplace_back(a[o][y2], o, y2);
      a[x2][y2] = 0;
      k--;
    }
    if (a[x1][y1] == 0 && 0 != a[x2][y2]) {
      ans.emplace_back(a[x2][y2], x1, y1);
      a[x1][y1] = a[x2][y2];
      a[x2][y2] = 0;
    }
    if (ans.size() > 20000) return cout << -1, 0;
  }
  cout << ans.size() << '\n';
  for (auto [a, b, c] : ans) cout << a << " " << b << " " << c << '\n';
}
