#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};
int goal, n, k, a[5][55];
pair<int, int> next(int x, int y) {
  if (x == 2) {
    if (y == n) return make_pair(3, n);
    return make_pair(2, y + 1);
  } else {
    if (y == 1) return make_pair(2, 1);
    return make_pair(3, y - 1);
  }
}
vector<tuple<int, int, int> > ans;
int main() {
  scanf("%d%d", &n, &k);
  for (int(i) = (1); (i) <= (4); (i) += (1))
    for (int(j) = (1); (j) <= (n); (j) += (1)) scanf("%d", &a[i][j]);
  if (k == 2 * n) {
    for (int(i) = (1); (i) <= (n); (i) += (1)) {
      if (a[1][i] == a[2][i]) {
        ans.push_back(tuple<int, int, int>(a[2][i], 1, i));
        goal++;
        a[2][i] = 0;
      }
      if (a[3][i] == a[4][i]) {
        ans.push_back(tuple<int, int, int>(a[3][i], 4, i));
        goal++;
        a[3][i] = 0;
      }
    }
    if (!goal) return !printf("-1");
  }
  int x = 2, y = 1;
  while (1) {
    if (goal == k) break;
    int nx, ny;
    tie(nx, ny) = next(x, y);
    if (a[x][y] > 0 && a[nx][ny] == 0) {
      ans.push_back(tuple<int, int, int>(a[x][y], nx, ny));
      swap(a[x][y], a[nx][ny]);
      if (nx == 2) {
        if (a[1][ny] == a[nx][ny]) {
          goal++;
          ans.push_back(tuple<int, int, int>(a[nx][ny], 1, ny));
          a[nx][ny] = 0;
        }
      } else if (nx == 3) {
        if (a[4][ny] == a[nx][ny]) {
          goal++;
          ans.push_back(tuple<int, int, int>(a[nx][ny], 4, ny));
          a[nx][ny] = 0;
        }
      }
    }
    x = nx, y = ny;
  }
  printf("%d\n", ans.size());
  for (tuple<int, int, int> a : ans)
    printf("%d %d %d\n", get<0>(a), get<1>(a), get<2>(a));
}
