#include <bits/stdc++.h>
const long long inf = 1e10;
const long long mod = 1e9 + 7;
const long long zero = 0;
const long long maxn = 2e3 + 5;
using namespace std;
long long mat[5][maxn], n, k, cnt;
vector<pair<pair<long long, long long>, long long> > v;
long long dif(long long a, long long b) { return abs(a - b); }
pair<long long, long long> nxt(int i, int j) {
  if (i == 2 and j == 1) return {3, 1};
  if (i == 3 and j == n) return {2, n};
  if (i == 2) return {i, j - 1};
  if (i == 3) return {i, j + 1};
}
pair<long long, long long> prev(int i, int j) { return nxt(j, i); }
void find_nxt() {
  long long iter1 = -1, iter2 = -1;
  for (int i = 1; i <= n; i++) {
    if (mat[2][i] == 0) {
      iter1 = 2;
      iter2 = i;
    }
    if (mat[3][i] == 0) {
      iter1 = 3;
      iter2 = i;
    }
  }
  long long l = iter1, r = iter2;
  for (int it = 1; it < 2 * n; it++) {
    pair<long long, long long> tmp = nxt(l, r);
    if (mat[tmp.first][tmp.second]) {
      v.push_back(make_pair(make_pair(mat[tmp.first][tmp.second], l), r));
      mat[l][r] = mat[tmp.first][tmp.second];
      mat[tmp.first][tmp.second] = 0;
    }
    l = tmp.first;
    r = tmp.second;
  }
}
void isval() {
  for (int i = 1; i <= n; i++) {
    if (mat[2][i] and mat[1][i] == mat[2][i]) {
      v.push_back(make_pair(make_pair(mat[1][i], 1), i));
      mat[2][i] = mat[1][i] = 0;
      k--;
    }
    if (mat[3][i] and mat[3][i] == mat[4][i]) {
      v.push_back(make_pair(make_pair(mat[3][i], 4), i));
      mat[3][i] = mat[4][i] = 0;
      k--;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) cin >> mat[i][j];
  isval();
  if (2 * n == k) {
    cout << -1;
    return 0;
  }
  while (k > 0 and cnt <= 499) {
    cnt++;
    find_nxt();
    isval();
  }
  if (cnt >= 401) {
    cout << -1;
    return 0;
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second
         << endl;
  }
  return 0;
}
