#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
string s;
int a[4][100];
vector<int> seq;
vector<pair<int, int> > poseq;
bool check() {
  for (int i = 0; i < n; i++) {
    if (a[1][i] != 0 || a[2][i] != 0) {
      return true;
    }
  }
  return false;
}
pair<int, int> next(pair<int, int> pos) {
  if (pos.first == 1) {
    if (pos.second != 0) {
      pos.second -= 1;
    } else {
      pos.first = 2;
    }
  } else {
    if (pos.second < n - 1) {
      pos.second += 1;
    } else {
      pos.first = 1;
    }
  }
  return pos;
}
void rotate() {
  int r, c;
  for (int i = 0; i < n; i++) {
    if (a[1][i] == 0) {
      r = 1;
      c = i;
    }
    if (a[2][i] == 0) {
      r = 2;
      c = i;
    }
  }
  pair<int, int> init = make_pair(r, c), prev = init, curr = next(init);
  while (init != curr) {
    if (a[curr.first][curr.second] != 0) {
      a[prev.first][prev.second] = a[curr.first][curr.second];
      seq.push_back(a[curr.first][curr.second]);
      a[curr.first][curr.second] = 0;
      poseq.push_back(prev);
    }
    prev = curr;
    curr = next(prev);
  }
}
void park() {
  for (int i = 0; i < n; i++) {
    if (a[1][i] > 0 && a[1][i] == a[0][i]) {
      seq.push_back(a[1][i]);
      poseq.push_back(make_pair(0, i));
      a[1][i] = 0;
    }
    if (a[2][i] > 0 && a[2][i] == a[3][i]) {
      seq.push_back(a[2][i]);
      poseq.push_back(make_pair(3, i));
      a[2][i] = 0;
    }
  }
}
void run() {
  cin >> n >> k;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  if (k == 2 * n) {
    bool allfull = true;
    for (int i = 0; i < n; i++) {
      if (a[1][i] == a[0][i] || a[2][i] == a[3][i]) {
        allfull = false;
        break;
      }
    }
    if (allfull) {
      cout << setprecision(30) << -1 << endl;
      return;
      ;
    }
  }
  park();
  while (check()) {
    rotate();
    park();
  }
  cout << setprecision(30) << seq.size() << endl;
  ;
  for (int i = 0; i < (int)seq.size(); i++) {
    cout << setprecision(30) << seq[i] << " ";
    ;
    cout << setprecision(30) << poseq[i].first + 1 << " ";
    ;
    cout << setprecision(30) << poseq[i].second + 1 << endl;
    ;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int tests = 1;
  for (int i = 1; i <= tests; i++) run();
  return 0;
}
