#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
int n, k, emp;
int ku[111][111];
struct node {
  int x, y, id;
};
vector<node> ans;
void parkin() {
  for (int i = 0; i < 2 * n; i++) {
    if (ku[1][i] && ku[1][i] == ku[0][i]) {
      node car;
      if (i >= n)
        car.x = 4, car.y = i % n + 1, car.id = ku[1][i];
      else
        car.x = 1, car.y = i % n + 1, car.id = ku[1][i];
      ans.push_back(car);
      ku[1][i] = 0;
      k--;
    }
  }
}
int canmov() {
  parkin();
  for (int i = 0; i < n * 2; i++)
    if (ku[1][i] == 0) return 1;
  return 0;
}
void mov() {
  vector<node> perv, next;
  node car;
  int t = ku[1][n * 2 - 1];
  for (int i = n * 2 - 1; i > 0; i--) {
    ku[1][i] = ku[1][i - 1];
    if (ku[1][i]) {
      car.id = ku[1][i];
      car.x = (i >= n ? 3 : 2);
      car.y = i % n + 1;
      if (i <= emp)
        perv.push_back(car);
      else
        next.push_back(car);
    }
  }
  ku[1][0] = t;
  if (t) {
    car.id = ku[1][0];
    car.x = 2;
    car.y = 1;
    perv.push_back(car);
  }
  for (int i = 0; i < perv.size(); i++) ans.push_back(perv[i]);
  for (int i = 0; i < next.size(); i++) ans.push_back(next[i]);
}
int main() {
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < n; j++) scanf("%d", &ku[i][j]);
    for (int i = 1; i >= 0; i--)
      for (int j = n * 2 - 1; j >= n; j--) scanf("%d", &ku[i][j]);
    if (!canmov()) {
      printf("-1\n");
      continue;
    }
    for (int i = 0; i < 2 * n; i++) {
      if (!ku[1][i]) {
        emp = i;
        break;
      }
    }
    while (k) {
      parkin();
      mov();
      emp = (emp + 1) % (2 * n);
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++) {
      int idd, xx, yy;
      idd = ans[i].id;
      xx = ans[i].x;
      yy = (ans[i].x == 3 || ans[i].x == 4) ? n - ans[i].y + 1 : ans[i].y;
      printf("%d %d %d\n", idd, xx, yy);
    }
  }
  return 0;
}
