#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
bool update;
int lot[5][MAXN + 5];
pair<int, int> pos[MAXN + 5];
vector<int> ans;
void drive(int idx, int first, int second) {
  update = true;
  assert(first == 1 || first == 4 || lot[first][second] == 0);
  ans.push_back(idx);
  ans.push_back(first);
  ans.push_back(second);
  lot[pos[idx].first][pos[idx].second] = 0;
  lot[first][second] = idx;
  pos[idx] = {first, second};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> lot[i][j];
      if (i != 1 && i != 4 && lot[i][j] != 0) {
        pos[lot[i][j]] = {i, j};
      }
    }
  }
  while (K > 0) {
    update = false;
    for (int i = 1; i <= N; i++) {
      if (lot[2][i] != 0) {
        if (lot[1][i] == lot[2][i]) {
          drive(lot[2][i], 1, i);
          K--;
        } else if (i == 1) {
          if (lot[3][1] == 0) {
            drive(lot[2][i], 3, 1);
          }
        } else {
          if (lot[2][i - 1] == 0) {
            drive(lot[2][i], 2, i - 1);
          }
        }
      }
    }
    for (int i = N; i >= 1; i--) {
      if (lot[3][i] != 0) {
        if (lot[4][i] == lot[3][i]) {
          drive(lot[3][i], 4, i);
          K--;
        } else if (i == N) {
          if (lot[2][N] == 0) {
            drive(lot[3][i], 2, N);
          }
        } else {
          if (lot[3][i + 1] == 0) {
            drive(lot[3][i], 3, i + 1);
          }
        }
      }
    }
    if (!update) break;
  }
  if (K) {
    cout << -1 << "\n";
  } else {
    cout << ans.size() / 3 << "\n";
    for (int i = 0; i < ans.size(); i += 3) {
      cout << ans[i] << ' ' << ans[i + 1] << ' ' << ans[i + 2] << '\n';
    }
  }
  return 0;
}
