#include <bits/stdc++.h>
using namespace std;
int n, k, f;
int g[4][100];
vector<pair<int, pair<int, int>>> m;
void moveCarsToDest() {
  for (int i = 0; i < n; i++) {
    if (g[1][i] != 0 && g[1][i] == g[0][i]) {
      m.push_back({g[1][i], {1, i + 1}});
      g[0][i] = 0;
      g[1][i] = 0;
      f++;
    }
    if (g[2][i] != 0 && g[2][i] == g[3][i]) {
      m.push_back({g[2][i], {4, i + 1}});
      g[2][i] = 0;
      g[3][i] = 0;
      f++;
    }
  }
}
pair<int, int> getNext(pair<int, int> q) {
  pair<int, int> p = {q.first, q.second};
  if (p.first == 1)
    p.second++;
  else
    p.second--;
  if (p.second >= n) {
    p.second = n - 1;
    p.first = 2;
  } else if (p.second < 0) {
    p.second = 0;
    p.first = 1;
  }
  return p;
}
void rotateCars() {
  pair<int, int> p = {1, 0};
  while (g[p.first][p.second] != 0) {
    p = getNext(p);
  }
  pair<int, int> s = p;
  do {
    pair<int, int> ne = getNext(p);
    if (ne == s) break;
    if (g[ne.first][ne.second] != 0) {
      m.push_back({g[ne.first][ne.second], {p.first + 1, p.second + 1}});
      g[p.first][p.second] = g[ne.first][ne.second];
      g[ne.first][ne.second] = 0;
    }
    p = ne;
  } while (p != s);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> g[i][j];
  moveCarsToDest();
  if (k == 2 * n && f == 0) {
    cout << -1 << "\n";
  } else {
    while (f < k) {
      rotateCars();
      moveCarsToDest();
    }
    cout << m.size() << "\n";
    for (pair<int, pair<int, int>> p : m) {
      cout << p.first << " " << p.second.first << " " << p.second.second
           << "\n";
    }
  }
}
