#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> a;
vector<tuple<int, int, int>> ans;
int n, k;
vector<bool> w;
void chk(int i, int j) {
  if (a[i][j] == 0) return;
  if (i == 1 && a[i][j] == a[i - 1][j]) {
    ans.push_back({a[i][j], i - 1, j});
    a[i][j] = 0;
    return;
  } else if (i == 2 && a[i][j] == a[i + 1][j]) {
    ans.push_back({a[i][j], i + 1, j});
    a[i][j] = 0;
    return;
  }
  return;
}
void way(int i, int j) {
  if (a[i][j] == 0) return;
  if (i == 1)
    if (j < n - 1) {
      way(i, j + 1);
      w[a[i][j]] = true;
      ans.push_back({a[i][j], i, j + 1});
      a[i][j + 1] = a[i][j];
      a[i][j] = 0;
    } else {
      way(i + 1, j);
      w[a[i][j]] = true;
      ans.push_back({a[i][j], i + 1, j});
      a[i + 1][j] = a[i][j];
      a[i][j] = 0;
    }
  else if (j > 0) {
    way(i, j - 1);
    w[a[i][j]] = true;
    ans.push_back({a[i][j], i, j - 1});
    a[i][j - 1] = a[i][j];
    a[i][j] = 0;
  } else {
    way(i - 1, j);
    w[a[i][j]] = true;
    ans.push_back({a[i][j], i - 1, j});
    a[i - 1][j] = a[i][j];
    a[i][j] = 0;
  }
}
int main() {
  cin >> n >> k;
  a.resize(4, vector<int>(n));
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  if (k == 2 * n) {
    bool f = true;
    for (int i = 0; f && i < n; i++)
      if (a[1][i] == a[0][i] || a[2][i] == a[3][i]) f = false;
    if (f) {
      cout << -1;
      return 0;
    }
  }
  for (int t = 0; t < 2 * n; t++) {
    for (int i = 1; i <= 2; i++)
      for (int j = 0; j < n; j++) chk(i, j);
    w.assign(k + 1, false);
    for (int i = 1; i <= 2; i++)
      for (int j = 0; j < n; j++)
        if (!w[a[i][j]]) way(i, j);
  }
  cout << ans.size() << endl;
  for (auto i : ans)
    cout << get<0>(i) << " " << get<1>(i) + 1 << " " << get<2>(i) + 1 << endl;
  return 0;
}
