#include <bits/stdc++.h>
using namespace std;
struct e {
  vector<vector<int>> parking;
  int left;
  int dist;
  vector<vector<int>> last;
  int i, r, c;
};
bool operator<(e a, e b) { return a.parking < b.parking; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> park(4, vector<int>(n));
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) cin >> park[i][j];
  }
  map<pair<int, int>, pair<int, int>> nxt;
  for (int i = 0; i < n - 1; i++) {
    nxt[make_pair(1, i)] = make_pair(1, i + 1);
  }
  for (int i = 1; i < n; i++) {
    nxt[make_pair(2, i)] = make_pair(2, i - 1);
  }
  nxt[make_pair(2, 0)] = make_pair(1, 0);
  nxt[make_pair(1, n - 1)] = make_pair(2, n - 1);
  int left = k;
  vector<vector<int>> ans;
  while (1) {
    for (int i = 0; i < n; i++) {
      if (park[1][i] == park[0][i] && park[1][i] != 0) {
        ans.push_back({park[0][i], 1, i + 1});
        park[1][i] = 0;
        left--;
      }
      if (park[2][i] == park[3][i] && park[3][i] != 0) {
        ans.push_back({park[2][i], 4, i + 1});
        park[2][i] = 0;
        left--;
      }
    }
    if (left == 2 * n) {
      cout << -1;
      return 0;
    }
    if (left == 0) break;
    bool m = 0;
    for (int i = 1; i < 3; i++) {
      for (int j = 0; j < n; j++) {
        if (park[i][j] != 0) {
          m = 1;
          function<void(int, int)> move = [&](int r, int c) {
            int nr, nc;
            tie(nr, nc) = nxt[make_pair(r, c)];
            if (park[nr][nc] != 0) {
              move(nr, nc);
            }
            ans.push_back({park[r][c], nr + 1, nc + 1});
            park[nr][nc] = park[r][c];
            park[r][c] = 0;
          };
          move(i, j);
          break;
        }
      }
      if (m) break;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i][0] << ' ' << ans[i][1] << ' ' << ans[i][2] << endl;
  }
  return 0;
}
