#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int maxn = 110;
int a[10][maxn], n, k;
vector<pair<int, pair<int, int> > > ans;
void Move(int x1, int y1, int x2, int y2) {
  ans.push_back({a[x1][y1], {x2, y2}});
  a[x2][y2] = a[x1][y1];
  a[x1][y1] = 0;
}
pair<int, int> getpos(int i) {
  if (i < n) return {2, i + 1};
  return {3, 2 * n - i};
}
void doxe() {
  for (int j = 1; j <= n; j++) {
    if (a[1][j] && a[2][j] == a[1][j]) {
      Move(2, j, 1, j);
      --k;
    }
    if (a[4][j] && a[3][j] == a[4][j]) {
      Move(3, j, 4, j);
      --k;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  doxe();
  if (k == 2 * n) return cout << -1, 0;
  while (k > 0) {
    int i = 0;
    while (a[getpos(i).first][getpos(i).second]) ++i;
    for (int j = (i + 1) % (2 * n); j != i; j = (j + 1) % (2 * n)) {
      if (a[getpos(j).first][getpos(j).second])
        Move(getpos(j).first, getpos(j).second,
             getpos((j - 1 + 2 * n) % (2 * n)).first,
             getpos((j - 1 + 2 * n) % (2 * n)).second);
    }
    doxe();
  }
  if (ans.size() > 20000)
    cout << -1;
  else {
    cout << ans.size() << "\n";
    for (auto& v : ans)
      cout << v.first << " " << v.second.first << " " << v.second.second
           << "\n";
  }
}
