#include <bits/stdc++.h>
using namespace std;
int n, k, ar[5][51], tmp[5][51], cnt = 0;
struct st {
  int car, r, c;
};
vector<st> ans;
void Rotate() {
  int r, c;
  for (int i = 2; i < 4; i++) {
    for (int j = 1; j <= n; j++) {
      tmp[i][j] = ar[i][j];
      if (ar[i][j] == 0) {
        r = i;
        c = j;
      }
    }
  }
  int val = 2 * n;
  while (val--) {
    if (r == 3) {
      if (c == 1) {
        ar[r][c] = tmp[2][1];
        if (tmp[2][1] != 0) ans.push_back({tmp[2][1], r, c});
        r = 2, c = 1;
      } else {
        ar[r][c] = tmp[r][c - 1];
        if (tmp[r][c - 1] != 0) ans.push_back({tmp[r][c - 1], r, c});
        c--;
      }
    } else {
      if (c == n) {
        ar[r][c] = tmp[3][n];
        if (tmp[3][n] != 0) ans.push_back({tmp[3][n], r, c});
        r = 3;
      } else {
        ar[r][c] = tmp[r][c + 1];
        if (tmp[r][c + 1] != 0) ans.push_back({tmp[r][c + 1], r, c});
        c++;
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", &ar[i][j]);
    }
  }
  if (k == 2 * n) {
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      if (ar[1][i] == ar[2][i] || ar[3][i] == ar[4][i]) flag = true;
    }
    if (!flag) {
      printf("-1\n");
      return 0;
    }
  }
  while (cnt < k) {
    for (int i = 1; i <= n; i++) {
      if (ar[1][i] == ar[2][i] && ar[1][i] != 0) {
        ans.push_back({ar[1][i], 1, i});
        ar[1][i] = ar[2][i] = 0;
        cnt++;
      }
      if (ar[3][i] == ar[4][i] && ar[3][i] != 0) {
        ans.push_back({ar[3][i], 4, i});
        ar[3][i] = ar[4][i] = 0;
        cnt++;
      }
    }
    Rotate();
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d %d\n", ans[i].car, ans[i].r, ans[i].c);
  }
}
