#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const long long mod = 1e9 + 7;
struct st {
  long long x, y, z;
};
long long a[4][1000];
vector<st> ans;
signed main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i < 4 + 1; i++)
    for (long long j = 1; j < n + 1; j++) scanf("%lld", &a[i][j]);
  long long f = 1;
  for (long long i = 1; i < 2 + 1; i++)
    for (long long j = 1; j < n + 1; j++) {
      if (i == 1 and a[1][j] == a[2][j]) f = 0;
      if (i == 2 and a[3][j] == a[4][j]) f = 0;
      if (a[i + 1][j] == 0) f = 0;
    }
  if (f == 1) {
    printf("-1\n");
    return 0;
  }
  while (1) {
    long long f = 1;
    for (long long j = 1; j < n + 1; j++) {
      long long y = (j == 1 ? 2 : 3);
      long long x = (j == 1 ? 1 : j - 1);
      if (a[3][j] == 0) continue;
      if (a[3][j] == a[4][j]) {
        ans.push_back(st{a[3][j], 4, j});
        a[3][j] = 0;
      } else if (a[y][x] == 0) {
        ans.push_back(st{a[3][j], y, x});
        a[y][x] = a[3][j];
        a[3][j] = 0;
      }
      f = 0;
    }
    for (long long j = n; j >= 1; j--) {
      long long y = (j == n ? 3 : 2);
      long long x = (j == n ? n : j + 1);
      if (a[2][j] == 0) continue;
      if (a[2][j] == a[1][j]) {
        ans.push_back(st{a[2][j], 1, j});
        a[2][j] = 0;
      } else if (a[y][x] == 0) {
        ans.push_back(st{a[2][j], y, x});
        a[y][x] = a[2][j];
        a[2][j] = 0;
      }
      f = 0;
    }
    if (f) break;
  }
  long long m = ans.size();
  printf("%lld\n", m);
  for (long long i = 0; i < m; i++) {
    printf("%lld %lld %lld\n", ans[i].x, ans[i].y, ans[i].z);
  }
  return 0;
}
