#include <bits/stdc++.h>
using namespace std;
const int M = 200005;
int n, k = 0;
int counter = 0;
int current[4][200];
vector<int> x, r, c;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &current[i][j]);
    }
  }
  if (k == 2 * n) {
    bool hasSpace = false;
    for (int j = 0; j < n; j++) {
      if (current[0][j] == current[1][j] || current[2][j] == current[3][j]) {
        hasSpace = true;
        break;
      }
    }
    if (hasSpace == false) {
      printf("-1");
      return 0;
    }
  }
  while (counter != k) {
    int pR = -1;
    int pC = -1;
    for (int j = 0; j < n; j++) {
      if (current[1][j] != 0 && current[0][j] == current[1][j]) {
        counter++;
        x.push_back(current[1][j]);
        r.push_back(0);
        c.push_back(j);
        current[1][j] = 0;
      }
      if (current[1][j] == 0) {
        pR = 1;
        pC = j;
      }
      if (current[2][j] != 0 && current[2][j] == current[3][j]) {
        counter++;
        x.push_back(current[2][j]);
        r.push_back(3);
        c.push_back(j);
        current[2][j] = 0;
      }
      if (current[2][j] == 0) {
        pR = 2;
        pC = j;
      }
    }
    for (int i = 0; i < 2 * n - 1; i++) {
      int nextR = -1;
      int nextC = -1;
      if (pR == 1) {
        if (pC == 0) {
          nextR = 2;
          nextC = 0;
        } else {
          nextR = 1;
          nextC = pC - 1;
        }
      } else if (pR == 2) {
        if (pC == n - 1) {
          nextR = 1;
          nextC = n - 1;
        } else {
          nextR = 2;
          nextC = pC + 1;
        }
      }
      if (current[nextR][nextC] != 0) {
        x.push_back(current[nextR][nextC]);
        r.push_back(pR);
        c.push_back(pC);
      }
      current[pR][pC] = current[nextR][nextC];
      current[nextR][nextC] = 0;
      pR = nextR;
      pC = nextC;
    }
  }
  printf("%d\n", x.size());
  for (int i = 0; i < x.size(); i++) {
    printf("%d %d %d\n", x[i], r[i] + 1, c[i] + 1);
  }
  return 0;
}
