#include <bits/stdc++.h>
using namespace std;
using std::string;
vector<pair<int, pair<int, int> > > v;
int a[5][52], n;
pair<int, int> s;
void find() {
  for (int(j) = 1; (j) <= (n); ++(j)) {
    for (int i = 2; i <= 3; i++) {
      if (a[i][j] == 0) s = make_pair(i, j);
    }
  }
}
void cycle() {
  int i = s.first, j = s.second, prej, prei, pre;
  int N = 2 * n - 1;
  while (N--) {
    if (i == 2)
      prej = j + 1;
    else
      prej = j - 1;
    prei = i;
    if (prei == 2 && prej == n + 1) {
      prej = n;
      prei = 3;
    }
    if (prei == 3 && prej == 0) {
      prej = 1;
      prei = 2;
    }
    pre = a[prei][prej];
    a[i][j] = pre;
    if (pre != 0) v.push_back(make_pair(pre, make_pair(i, j)));
    if (i == 2) {
      j += 1;
      if (j == n + 1) {
        j = n;
        i = 3;
      }
    } else {
      j -= 1;
      if (j == 0) {
        i = 2;
        j = 1;
      }
    }
  }
  if (s.first == 2) {
    s.second = s.second - 1;
    if (s.second == 0) {
      s.first = 3;
      s.second = 1;
    }
  } else {
    s.second = s.second + 1;
    if (s.second == n + 1) {
      s.second = n;
      s.first = 2;
    }
  }
  a[s.first][s.second] = 0;
}
int main() {
  int k;
  cin >> n >> k;
  s.first == 0;
  for (int(i) = 1; (i) <= (4); ++(i)) {
    for (int(j) = 1; (j) <= (n); ++(j)) {
      cin >> a[i][j];
    }
  }
  int cnt = 0;
  while (cnt < 2 * n) {
    for (int j = 1; j <= n; j++) {
      if (a[2][j] == a[1][j]) {
        if (a[2][j] != 0) v.push_back(make_pair(a[2][j], make_pair(1, j)));
        a[2][j] = 0;
      }
      if (a[3][j] == a[4][j]) {
        if (a[3][j] != 0) v.push_back(make_pair(a[3][j], make_pair(4, j)));
        a[3][j] = 0;
      }
    }
    if (cnt == 0) {
      find();
      if (s.first == 0) break;
    }
    cnt++;
    cycle();
  }
  int j = 1;
  for (j = 1; j <= n; j++) {
    if (a[2][j] != 0 || a[3][j] != 0) break;
  }
  if (j > n) {
    cout << v.size() << endl;
    for (int(i) = 0; (i) < (v.size()); ++(i))
      cout << v[i].first << " " << (v[i].second).first << " "
           << (v[i].second).second << endl;
  } else
    cout << -1;
}
