#include <bits/stdc++.h>
using namespace std;
bool done[1000] = {0};
const int INF = 1e9;
int n, k, A[4][1000];
vector<tuple<int, int, int>> M;
void show() {
  cout << M.size() << '\n';
  for (auto V : M) {
    int a, b, c;
    tie(a, b, c) = V;
    cout << c << ' ' << a << ' ' << b << '\n';
  }
}
int main() {
  vector<pair<int, int>> cyc;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cyc.push_back({1, i});
  for (int i = 0; i < n; ++i) cyc.push_back({2, n - i - 1});
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < n; ++j) cin >> A[i][j];
  if (n == 1) {
    if (k == 2) {
      if (A[1][0] != A[0][0] or A[2][0] != A[3][0])
        return cout << "-1\n", 0;
      else
        return 0 * printf("2\n1 1 %d\n%d 4 1\n", A[1][0], A[2][0]);
    } else {
      int reach = A[0][0] ? 0 : 3;
      int cur = A[1][0] ? 1 : 2;
      int num = A[cur][0];
      while (cur != reach) {
        cur += reach > cur ? 1 : -1;
        M.emplace_back(cur + 1, 1, num);
      }
      show();
      return 0;
    }
  }
  auto park = [&] {
    for (int i = 0; i < n; ++i)
      if (A[1][i] and A[0][i] == A[1][i])
        M.emplace_back(1, i + 1, A[0][i]), A[1][i] = 0, --k;
    for (int i = 0; i < n; ++i)
      if (A[2][i] and A[2][i] == A[3][i])
        M.emplace_back(4, i + 1, A[2][i]), A[2][i] = 0, --k;
  };
  park();
  if (count(A[1], A[1] + n, 0) + count(A[2], A[2] + n, 0) == 0) {
    bool fail = 0;
    for (int i = 0; i < n; ++i) fail |= A[0][i] != A[1][i];
    for (int i = 0; i < n; ++i) fail |= A[2][i] != A[3][i];
    if (fail)
      return cout << "-1\n", 0;
    else
      for (int i = 0; i < n; ++i)
        M.emplace_back(1, i + 1, A[0][i]), M.emplace_back(4, i + 1, A[3][i]);
    show();
    return 0;
  }
  int idx = find_if(cyc.begin(), cyc.end(),
                    [&](pair<int, int> I) {
                      int i, j;
                      tie(i, j) = I;
                      return A[i][j] == 0;
                    }) -
            cyc.begin();
  while (k) {
    park();
    for (int d = idx; (d + 1) % (2 * n) != idx;) {
      int ne = (d + 1) % cyc.size();
      int x, y, nx, ny;
      tie(x, y) = cyc[d], tie(nx, ny) = cyc[ne];
      assert(A[x][y] == 0);
      if (A[nx][ny])
        A[x][y] = A[nx][ny], A[nx][ny] = 0,
        M.emplace_back(x + 1, y + 1, A[x][y]);
      d = ne;
    }
    idx = (idx - 1 + cyc.size()) % cyc.size();
  }
  show();
}
