#include <bits/stdc++.h>
using namespace std;
int n, k, f;
int g[4][55];
vector<pair<int, pair<int, int> > > ans;
void tryfit() {
  for (int i = 0; i < n; i++) {
    if (g[1][i] and g[1][i] == g[0][i]) {
      ans.push_back({g[1][i], {1, i + 1}});
      g[1][i] = 0;
      k--;
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[2][i] and g[2][i] == g[3][i]) {
      ans.push_back({g[2][i], {4, i + 1}});
      g[2][i] = 0;
      k--;
    }
  }
}
void rot() {
  int r = -1, c = 0;
  for (int i = 1; i <= 2; i++)
    for (int j = 0; j < n; j++)
      if (!g[i][j]) r = i, c = j;
  if (r == -1) {
    f = 1;
    return;
  }
  for (int i = 0; i < 2 * n - 1; i++) {
    int lr = r, lc = c;
    c += (r == 1) ? 1 : -1;
    if (c > n - 1) c = n - 1, r = 2;
    if (c < 0) c = 0, r = 1;
    if (g[r][c]) {
      ans.push_back({g[r][c], {lr + 1, lc + 1}});
      swap(g[r][c], g[lr][lc]);
    }
  }
}
void solv() {
  tryfit();
  while (k and ans.size() <= 20000 and !f) {
    rot();
    tryfit();
  }
  if (ans.size() > 20000) f = 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> g[i][j];
  solv();
  if (!f) {
    cout << (int)ans.size() << "\n";
    for (auto x : ans)
      cout << x.first << ' ' << x.second.first << ' ' << x.second.second
           << "\n";
  } else {
    printf("-1\n");
  }
  return 0;
}
