#include <bits/stdc++.h>
using namespace std;
int n, k, s, a[5][205];
struct node {
  int id, x, y;
};
vector<node> ans;
inline void park() {
  for (int i = 0; i <= 2 * n - 1; ++i)
    if (a[1][i] && a[1][i] == a[0][i]) {
      ans.push_back(node{a[1][i], i / n ? 4 : 1, i % n + 1});
      a[1][i] = 0;
      k--;
    }
}
inline bool judge() {
  park();
  for (int i = 0; i <= 2 * n - 1; ++i)
    if (!a[1][i]) return 1;
  return 0;
}
inline void turn() {
  vector<node> t1, t2;
  int t = a[1][2 * n - 1];
  for (int i = 2 * n - 1; i >= 1; --i) {
    a[1][i] = a[1][i - 1];
    if (a[1][i]) {
      if (i > s)
        t1.push_back(node{a[1][i], i / n ? 3 : 2, i % n + 1});
      else
        t2.push_back(node{a[1][i], i / n ? 3 : 2, i % n + 1});
    }
  }
  a[1][0] = t;
  if (t) t2.push_back(node{t, 2, 1});
  int sz1 = t1.size(), sz2 = t2.size();
  for (int i = 0; i <= sz2 - 1; ++i) ans.push_back(t2[i]);
  for (int i = 0; i <= sz1 - 1; ++i) ans.push_back(t1[i]);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i <= n - 1; ++i) scanf("%d", &a[0][i]);
  for (int i = 0; i <= n - 1; ++i) scanf("%d", &a[1][i]);
  for (int i = 2 * n - 1; i >= n; --i) scanf("%d", &a[1][i]);
  for (int i = 2 * n - 1; i >= n; --i) scanf("%d", &a[0][i]);
  if (!judge()) return puts("-1"), 0;
  for (int i = 0; i <= 2 * n - 1; ++i)
    if (!a[1][i]) {
      s = i;
      break;
    }
  while (k) {
    turn();
    park();
    s = (s + 1) % (2 * n);
  }
  int sz = ans.size();
  printf("%d\n", sz);
  for (int i = 0; i < sz; ++i) {
    if (ans[i].x == 3 || ans[i].x == 4) ans[i].y = n - ans[i].y + 1;
    printf("%d %d %d\n", ans[i].id, ans[i].x, ans[i].y);
  }
  return 0;
}
