#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18 + 9;
const long long MAXN = 1e6 + 7;
const long long MAXN1 = 2e3 + 7;
const long long MOD = 1e9 + 7;
const long long ST = 157;
const long long ST1 = 199;
const long double EPS = 1e-9;
const long long BLOCK = 138;
void solve();
signed main() {
  srand('a' + 'l' + 'e' + 'x' + 'X' + '5' + '1' + '2');
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
bool good(vector<int> &v1, vector<int> &v2) {
  for (auto i : v1) {
    if (i != 0) return 1;
  }
  for (auto i : v2) {
    if (i != 0) return 1;
  }
  return 0;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v1(n), v2(n), v3(n), v4(n);
  for (int i = 0; i < n; i++) {
    cin >> v1[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> v2[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> v3[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> v4[i];
  }
  vector<pair<int, pair<int, int>>> ans;
  while (good(v2, v3)) {
    vector<bool> used(k + 1);
    int k = ans.size();
    for (int i = 0; i < n; i++) {
      if (v1[i] == v2[i] && v1[i] != 0) {
        v2[i] = 0;
        ans.emplace_back(v1[i], make_pair(1, i + 1));
      }
      if (v3[i] == v4[i] && v4[i] != 0) {
        v3[i] = 0;
        ans.emplace_back(v4[i], make_pair(4, i + 1));
      }
    }
    int i = 0;
    for (; i < n - 1; i++) {
      if (v2[i + 1] == 0 && v2[i] != 0 && !used[v2[i]]) {
        used[v2[i]] = 1;
        v2[i + 1] = v2[i];
        v2[i] = 0;
        ans.emplace_back(v2[i + 1], make_pair(2, i + 2));
        i++;
      }
    }
    if (i == n - 1) {
      if (v3[i] == 0 && v2[i] != 0 && !used[v2[i]]) {
        used[v2[i]] = 1;
        v3[i] = v2[i];
        v2[i] = 0;
        ans.emplace_back(v3[i], make_pair(3, n));
        i--;
      }
    }
    i = n - 1;
    for (; i > 0; i--) {
      if (v3[i - 1] == 0 && v3[i] != 0 && !used[v3[i]]) {
        used[v3[i]] = 1;
        v3[i - 1] = v3[i];
        v3[i] = 0;
        ans.emplace_back(v3[i - 1], make_pair(3, i));
        i--;
      }
    }
    if (i == 0) {
      if (v2[0] == 0 && v3[0] != 0 && !used[v3[0]]) {
        used[v3[0]] = 1;
        v2[0] = v3[0];
        v3[0] = 0;
        ans.emplace_back(v2[0], make_pair(2, 1));
      }
    }
    if (k == ans.size()) {
      cout << -1;
      return;
    }
  }
  cout << ans.size() << "\n";
  for (auto i : ans) {
    cout << i.first << " " << i.second.first << " " << i.second.second << "\n";
  }
}
