#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
template <typename T, typename T2>
inline void _max(T &a, T2 b) {
  a = max((T)a, (T)b);
}
template <typename T, typename T2>
inline void _min(T &a, T2 b) {
  a = min((T)a, (T)b);
}
const int MAX = 55;
int n, k;
int mx[4][MAX];
int nPlaced = 0;
pair<int, int> e;
void clear() {
  nPlaced = 0;
  e = pair<int, int>({-1, -1});
}
void read() {
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) scanf("%d", &mx[i][j]);
}
struct Move {
  int id, x, y;
};
void checkPark(vector<Move> &res) {
  for (int i = 0; i < n; i++) {
    if (mx[1][i] && mx[1][i] == mx[0][i]) {
      res.push_back({mx[1][i], 0, i});
      mx[1][i] = mx[0][i] = 0;
      nPlaced++;
    }
    if (mx[2][i] && mx[2][i] == mx[3][i]) {
      res.push_back({mx[2][i], 3, i});
      mx[2][i] = mx[3][i] = 0;
      nPlaced++;
    }
  }
}
void move(vector<Move> &res) {
  for (int i = 0; i < 2 * n - 1; i++) {
    pair<int, int> from = {-1, -1};
    if (e.first == 1 && e.second == 0)
      from = {2, 0};
    else if (e.first == 2 && e.second == n - 1)
      from = {1, n - 1};
    else if (e.first == 1)
      from = {e.first, e.second - 1};
    else
      from = {e.first, e.second + 1};
    if (mx[from.first][from.second])
      res.push_back({mx[from.first][from.second], e.first, e.second}),
          swap(mx[e.first][e.second], mx[from.first][from.second]);
    e = from;
  }
}
void solve() {
  vector<Move> res;
  checkPark(res);
  for (int i = 1; i <= 2; i++)
    for (int j = 0; j < n; j++)
      if (mx[i][j] == 0) e = {i, j};
  if (e.first == -1) return void(printf("-1\n"));
  while (nPlaced < k) {
    move(res);
    checkPark(res);
  }
  printf("%d\n", res.size());
  for (auto &m : res) printf("%d %d %d\n", m.id, m.x + 1, m.y + 1);
}
int main() {
  while (scanf("%d%d", &n, &k) == 2) {
    clear();
    read();
    solve();
    return 0;
  }
  return 0;
}
