#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
int n, k;
int a[5][207];
struct mm {
  mm() {}
  mm(int id, int x, int y) : id(id), x(x), y(y) {}
  int id;
  int x;
  int y;
};
vector<mm> res;
int yes = 0;
void check() {
  for (int i = 1; i <= n; i++) {
    if (a[2][i] && a[1][i] == a[2][i]) {
      res.emplace_back(mm(a[2][i], 1, i));
      yes++;
      a[2][i] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[3][i] && a[3][i] == a[4][i]) {
      res.emplace_back(mm(a[3][i], 4, i));
      yes++;
      a[3][i] = 0;
    }
  }
}
void move() {
  int x, y;
  for (int i = 1; i <= n; i++) {
    if (a[2][i] == 0) {
      x = 2;
      y = i;
      break;
    }
    if (a[3][i] == 0) {
      x = 3;
      y = i;
      break;
    }
  }
  if (x == 2) {
    for (int i = y; i >= 2; i--) {
      if (a[2][i - 1] != 0) {
        res.emplace_back(mm(a[2][i - 1], 2, i));
        swap(a[2][i - 1], a[2][i]);
      }
    }
    if (a[3][1] != 0) {
      res.emplace_back(mm(a[3][1], 2, 1));
      swap(a[2][1], a[3][1]);
    }
    for (int i = 1; i < n; i++) {
      if (a[3][i + 1] != 0) {
        res.emplace_back(mm(a[3][i + 1], 3, i));
        swap(a[3][i + 1], a[3][i]);
      }
    }
    if (y != n && a[2][n] != 0) {
      res.emplace_back(mm(a[2][n], 3, n));
      swap(a[2][n], a[3][n]);
    }
    for (int i = n - 1; i > y; i--) {
      if (a[2][i] != 0) {
        res.emplace_back(mm(a[2][i], 2, i + 1));
        swap(a[2][i], a[2][i + 1]);
      }
    }
  } else {
    for (int i = y + 1; i <= n; i++) {
      if (a[3][i] != 0) {
        res.emplace_back(mm(a[3][i], 3, i - 1));
        swap(a[3][i - 1], a[3][i]);
      }
    }
    if (a[2][n] != 0) {
      res.emplace_back(mm(a[2][n], 3, n));
      swap(a[2][n], a[3][n]);
    }
    for (int i = n; i > 1; i--) {
      if (a[2][i - 1] != 0) {
        res.emplace_back(mm(a[2][i - 1], 2, i));
        swap(a[2][i], a[2][i - 1]);
      }
    }
    if (y != 1 && a[3][1] != 0) {
      res.emplace_back(mm(a[3][1], 2, 1));
      swap(a[2][1], a[3][1]);
    }
    for (int i = 2; i < y; i++) {
      if (a[3][i] != 0) {
        res.emplace_back(mm(a[3][i], 3, i - 1));
        swap(a[3][i], a[3][i - 1]);
      }
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= 4; i++) {
    if (i == 1 || i == 4) {
      for (int j = 1; j <= n; j++) {
        cin >> a[i][j];
      }
    } else {
      for (int j = 1; j <= n; j++) {
        cin >> a[i][j];
      }
    }
  }
  check();
  if (k == 2 * n && res.size() == 0) {
    printf("-1\n");
    return 0;
  }
  while (yes < k) {
    move();
    check();
  }
  printf("%d\n", res.size());
  for (int i = 0; i < res.size(); i++) {
    printf("%d %d %d\n", res[i].id, res[i].x, res[i].y);
  }
  return 0;
}
