#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 50;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
int c[6][250];
struct node {
  int id, x, y;
  node(int i = 0, int j = 0, int d = 0) : id(i), x(j), y(d) {}
};
vector<node> ans;
queue<node> qu;
bool in(int n) {
  bool has = false;
  for (int i = 1; i <= n; ++i)
    if (c[2][i]) {
      if (c[2][i] == c[1][i]) {
        ans.push_back(node(c[2][i], 1, i));
        c[2][i] = 0;
        has = true;
      } else {
        qu.push(node(c[2][i], 2, i));
      }
    }
  for (int i = 1; i <= n; ++i)
    if (c[3][i]) {
      if (c[3][i] == c[4][i]) {
        ans.push_back(node(c[3][i], 4, i));
        c[3][i] = 0;
        has = true;
      } else {
        qu.push(node(c[3][i], 3, i));
      }
    }
  return has;
}
bool check(int x, int y) {
  int dy = y, dx = (x == 2 ? 1 : 4);
  if (c[x][y] and c[x][y] == c[dx][dy]) {
    ans.push_back(node(c[x][y], dx, dy));
    c[x][y] = 0;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= 4; ++i)
    for (int j = 1; j <= n; ++j) cin >> c[i][j];
  bool has = in(n);
  if (k == 2 * n and !has) {
    cout << -1;
    return 0;
  }
  while (!qu.empty()) {
    node use = qu.front();
    qu.pop();
    int x = use.x, y = use.y;
    int dx = x, dy = y + (x == 2 ? 1 : -1);
    if (dx == 2 and dy > n) {
      dx = 3, dy = n;
    } else if (dx == 3 and dy < 1) {
      dx = 2;
      dy = 1;
    }
    if (!c[dx][dy]) {
      swap(c[dx][dy], c[x][y]);
      ans.push_back(node(use.id, dx, dy));
      if (!check(dx, dy)) qu.push(node(use.id, dx, dy));
    } else
      qu.push(use);
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].id << " " << ans[i].x << " " << ans[i].y << "\n";
  return 0;
}
