#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 55;
int n, k, f;
int g[4][N];
vector<pair<int, pair<int, int> > > ans;
void print() {
  printf("\n");
  for (int i = 1; i <= 2; i++) {
    for (int j = 0; j < n; j++) printf("%d ", g[i][j]);
    printf("\n");
  }
  printf("\n");
}
void tryfit() {
  for (int i = 0; i < n; i++) {
    if (g[1][i] and g[1][i] == g[0][i]) {
      ans.push_back({g[1][i], {1, i + 1}});
      g[1][i] = 0;
      k--;
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[2][i] and g[2][i] == g[3][i]) {
      ans.push_back({g[2][i], {4, i + 1}});
      g[2][i] = 0;
      k--;
    }
  }
}
void rot() {
  int r = -1, c = 0;
  for (int i = 1; i <= 2; i++)
    for (int j = 0; j < n; j++)
      if (!g[i][j]) r = i, c = j;
  if (r == -1) {
    f = 1;
    return;
  }
  for (int i = 0; i < 2 * n - 1; i++) {
    int lr = r, lc = c;
    c += (r == 1) ? 1 : -1;
    if (c > n - 1) c = n - 1, r = 2;
    if (c < 0) c = 0, r = 1;
    if (g[r][c]) {
      ans.push_back({g[r][c], {lr + 1, lc + 1}});
      swap(g[r][c], g[lr][lc]);
    }
  }
}
void solv() {
  tryfit();
  while (k and ans.size() <= 20000 and !f) {
    rot();
    tryfit();
  }
  if (ans.size() > 20000) f = 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) scanf("%d", &g[i][j]);
  solv();
  if (!f) {
    printf("%d\n", (int)ans.size());
    for (auto x : ans)
      printf("%d %d %d\n", x.first, x.second.first, x.second.second);
  } else {
    printf("-1\n");
  }
  return 0;
}
