#include <bits/stdc++.h>
using namespace std;
int a[5][55];
int n, k;
int mx(int x, int y) {
  if (x == 2) return (y == 1) ? 3 : 2;
  if (x == 3) return (y == n) ? 2 : 3;
}
int my(int x, int y) {
  if (x == 2) return (y == 1) ? 1 : (y - 1);
  if (x == 3) return (y == n) ? n : (y + 1);
}
int _mx(int x, int y) {
  if (x == 2) return (y == n) ? 3 : 2;
  if (x == 3) return (y == 1) ? 2 : 3;
}
int _my(int x, int y) {
  if (x == 2) return (y == n) ? n : (y + 1);
  if (x == 3) return (y == 1) ? 1 : (y - 1);
}
struct node {
  int t, x, y;
} step[20005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  }
  int K = k, cnt = 0;
  for (int i = 2; i <= 3; i++) {
    int l = (i == 2) ? 1 : 4;
    for (int j = 1; j <= n; j++) {
      if (a[i][j] > 0 && a[i][j] == a[l][j]) {
        step[++cnt] = (node){a[i][j], l, j};
        a[i][j] = 0;
        K--;
      }
    }
  }
  if (K == (n << 1)) {
    printf("-1");
    return 0;
  }
  int sx, sy;
  for (int i = 2; i <= 3; i++) {
    for (int j = 1; j <= n; j++) {
      int xx = mx(i, j), yy = my(i, j);
      if (a[xx][yy] == 0) {
        sx = i;
        sy = j;
        break;
      }
    }
  }
  while (K) {
    int x = sx, y = sy;
    int xx = mx(x, y), yy = my(x, y);
    a[xx][yy] = a[x][y];
    a[x][y] = 0;
    if (a[xx][yy] > 0) step[++cnt] = (node){a[xx][yy], xx, yy};
    int l = (xx == 2) ? 1 : 4;
    if (a[xx][yy] > 0 && a[xx][yy] == a[l][yy]) {
      step[++cnt] = (node){a[xx][yy], l, yy};
      a[xx][yy] = 0;
      K--;
    }
    sx = _mx(x, y);
    sy = _my(x, y);
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++)
    printf("%d %d %d\n", step[i].t, step[i].x, step[i].y);
  return 0;
}
