#include <bits/stdc++.h>
using namespace std;
void pp(long long n, long long a[5][51]) {
  cout << "PARKING\n";
  for (long long i = 1; i < 5; i++) {
    for (long long j = 1; j < n + 1; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[5][51];
  for (long long i = 1; i < 5; i++)
    for (long long j = 1; j < n + 1; j++) cin >> a[i][j];
  vector<pair<long long, pair<long long, long long> > > moves;
  long long steps = 0;
  while (k) {
    for (long long i = 1; i < n + 1; i++) {
      if (a[2][i] == 0)
        continue;
      else if (a[1][i] == a[2][i]) {
        moves.push_back(make_pair(a[2][i], make_pair(1, i)));
        k--;
        a[2][i] = 0;
      } else if (i < n && a[2][i + 1] == 0) {
        moves.push_back(make_pair(a[2][i], make_pair(2, i + 1)));
        a[2][i + 1] = a[2][i];
        a[2][i] = 0;
      } else if (i == n && a[3][i] == 0) {
        moves.push_back(make_pair(a[2][i], make_pair(3, i)));
        a[3][i] = a[2][i];
        a[2][i] = 0;
      } else {
      }
    }
    for (long long i = n; i >= 1; i--) {
      if (a[3][i] == 0)
        continue;
      else if (a[4][i] == a[3][i]) {
        moves.push_back(make_pair(a[3][i], make_pair(4, i)));
        k--;
        a[3][i] = 0;
      } else if (i > 1 && a[3][i - 1] == 0) {
        moves.push_back(make_pair(a[3][i], make_pair(3, i - 1)));
        a[3][i - 1] = a[3][i];
        a[3][i] = 0;
      } else if (i == 1 && a[2][i] == 0) {
        moves.push_back(make_pair(a[3][i], make_pair(2, i)));
        a[2][i] = a[3][i];
        a[3][i] = 0;
      } else {
      }
    }
    steps++;
    if (steps > 20000) break;
  }
  if (k > 0)
    cout << -1;
  else {
    long long c, x, y;
    cout << moves.size() << "\n";
    for (long long i = 0; i < moves.size(); i++) {
      c = moves[i].first;
      x = moves[i].second.first;
      y = moves[i].second.second;
      cout << c << " " << x << " " << y << "\n";
    }
  }
  return 0;
}
