#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, k, s[5][60], num_solved;
vector<tuple<int, int, int>> ans;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  cin >> n >> k;
  for (int i = 0; i <= 3; ++i)
    for (int j = 1; j <= n; ++j) cin >> s[i][j];
  auto find_nxt = [&](int now_r, int now_c, int& nxt_r, int& nxt_c) {
    if (now_r == 1) {
      nxt_r = 1, nxt_c = now_c + 1;
      if (nxt_c == n + 1) nxt_r = 2, nxt_c = n;
    } else {
      nxt_r = 2, nxt_c = now_c - 1;
      if (nxt_c == 0) nxt_r = 1, nxt_c = 1;
    }
  };
  auto rotate = [&](int r, int c) {
    int initial = s[r][c];
    int now_r = r, now_c = c;
    int nxt_r = -1, nxt_c = -1;
    find_nxt(now_r, now_c, nxt_r, nxt_c);
    while (nxt_r != r or nxt_c != c) {
      if (s[nxt_r][nxt_c]) ans.emplace_back(s[nxt_r][nxt_c], now_r, now_c);
      s[now_r][now_c] = s[nxt_r][nxt_c];
      now_r = nxt_r, now_c = nxt_c;
      find_nxt(now_r, now_c, nxt_r, nxt_c);
    }
    s[now_r][now_c] = initial;
  };
  auto go = [&]() {
    for (int i = 1; i <= 2; ++i)
      for (int j = 1; j <= n; ++j)
        if ((s[i][j] == s[i ^ 1][j]) and s[i][j]) {
          ++num_solved;
          ans.emplace_back(s[i][j], i ^ 1, j);
          s[i][j] = 0;
        }
    bool rotated = false;
    for (int i = 1; i <= 2; ++i) {
      for (int j = 1; j <= n; ++j)
        if (s[i][j] == 0) {
          rotate(i, j);
          rotated = true;
          break;
        }
      if (rotated) break;
    }
  };
  go();
  if (k == 2 * n and num_solved == 0) {
    cout << -1 << '\n';
    return 0;
  }
  while (num_solved < k) go();
  cout << ans.size() << '\n';
  for (int i = 0; i < (int)ans.size(); ++i) {
    int a, b, c;
    tie(a, b, c) = ans[i];
    cout << a << ' ' << b + 1 << ' ' << c << '\n';
  }
}
