#include <bits/stdc++.h>
using namespace std;
int a[4][55];
int ans[20005][3];
int res = 0, t = 0;
void add(int x, int i, int j) {
  res++;
  ans[t][0] = x;
  ans[t][1] = i + 1;
  ans[t++][2] = j + 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    if (a[0][i] != 0 && a[0][i] == a[1][i]) {
      k--;
      add(a[0][i], 0, i);
      a[1][i] = 0;
    }
  for (int i = 0; i < n; i++)
    if (a[2][i] != 0 && a[2][i] == a[3][i]) {
      k--;
      add(a[2][i], 3, i);
      a[2][i] = 0;
    }
  if (k == 2 * n) {
    cout << -1 << endl;
    return 0;
  }
  while (k > 0) {
    for (int i = 0; i < 2 * n; i++) {
      int p, q;
      if (i < n)
        p = 1, q = i;
      else
        p = 2, q = 2 * n - 1 - i;
      if (a[p][q] == 0) continue;
      if (a[p][q] == a[p ^ 1][q]) {
        k--;
        add(a[p][q], p ^ 1, q);
        a[p][q] = 0;
      } else {
        int x, y;
        if ((i + 2 * n - 1) % (2 * n) < n)
          x = 1, y = (i + 2 * n - 1) % (2 * n);
        else
          x = 2, y = 2 * n - 1 - (i + 2 * n - 1) % (2 * n);
        if (a[x][y] != 0) continue;
        add(a[p][q], x, y);
        a[x][y] = a[p][q];
        a[p][q] = 0;
      }
    }
  }
  cout << res << endl;
  for (int i = 0; i < t; i++)
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << endl;
}
