#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
  node(int x_ = 0, int y_ = 0) {
    x = x_;
    y = y_;
  }
  bool operator^(const node &t) const {
    return (abs(x - t.x) + abs(y - t.y)) == 1;
  }
  bool operator==(const node &t) const { return x == t.x && y == t.y; }
} st[205], ed[205], pos[205];
int b[205];
pair<int, node> ans[20010];
int n, k;
int a[5][205];
bool allno() {
  for (int i = 1; i <= k; ++i)
    if (st[i] ^ ed[i]) return false;
  return true;
}
int main() {
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 1; i <= 4; ++i) {
      for (int j = 1; j <= n; ++j) {
        scanf("%d", &a[i][j]);
        if (i == 1 || i == 4)
          ed[a[i][j]] = node(i, j);
        else
          st[a[i][j]] = node(i, j);
      }
    }
    if (k == 2 * n && allno())
      puts("-1");
    else {
      int len = 0, tot = 0;
      for (int i = 1; i <= n; ++i) {
        b[len] = a[2][i];
        pos[len] = node(2, i);
        len++;
      }
      for (int i = n; i >= 1; --i) {
        b[len] = a[3][i];
        pos[len] = node(3, i);
        len++;
      }
      while (true) {
        bool flag = true;
        for (int i = 0; i < len; ++i)
          if (b[i] > 0) flag = false;
        if (flag) break;
        for (int i = 0; i < len; ++i)
          if (b[i] > 0 && (pos[i] ^ ed[b[i]])) {
            ans[++tot] = make_pair(b[i], ed[b[i]]);
            b[i] = 0;
          }
        int x = 0;
        for (int i = 0; i < len; ++i)
          if (b[i] == 0) {
            x = i;
            break;
          }
        int now = (x - 1 + len) % len;
        while (now != x) {
          if (b[now] > 0) ans[++tot] = make_pair(b[now], pos[(now + 1) % len]);
          b[(now + 1) % len] = b[now];
          now = (now - 1 + len) % len;
        }
        b[(now + 1) % len] = 0;
      }
      printf("%d\n", tot);
      for (int i = 1; i <= tot; ++i)
        printf("%d %d %d\n", ans[i].first, ans[i].second.x, ans[i].second.y);
    }
  }
}
