#include <bits/stdc++.h>
using namespace std;
struct str {
  int i, r, c;
  str(int ii, int rr, int cc) {
    i = ii;
    r = rr;
    c = cc;
  }
};
pair<int, int> nnext[10][100];
vector<str> ans;
int board[10][100];
int n;
void solve() {
  for (int i = 0; i < int(n); i++)
    if (board[0][i] == board[1][i] && board[0][i] != 0) {
      ans.push_back(str(board[1][i], 1, i + 1));
      board[1][i] = 0;
    }
  for (int i = 0; i < int(n); i++)
    if (board[2][i] == board[3][i] && board[3][i] != 0) {
      ans.push_back(str(board[2][i], 4, i + 1));
      board[2][i] = 0;
    }
}
int main() {
  int k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < int(4); i++)
    for (int j = 0; j < int(n); j++) scanf("%d", &board[i][j]);
  for (int i = 0; i < n - 1; i++) nnext[1][i] = make_pair(1, i + 1);
  for (int i = n - 1; i >= 1; i--) nnext[2][i] = make_pair(2, i - 1);
  nnext[1][n - 1] = make_pair(2, n - 1);
  nnext[2][0] = make_pair(1, 0);
  solve();
  bool p = false;
  for (int i = 0; i < int(n); i++) {
    if (board[1][i] == 0 || board[2][i] == 0) p = true;
  }
  if (!p)
    printf("-1\n");
  else {
    while (true) {
      bool done = true;
      for (int i = 1; i <= 2; i++) {
        bool q = false;
        for (int j = 0; j < int(n); j++) {
          if (board[i][j] != 0 &&
              board[nnext[i][j].first][nnext[i][j].second] == 0) {
            done = false;
            ans.push_back(str(board[i][j], nnext[i][j].first + 1,
                              nnext[i][j].second + 1));
            board[nnext[i][j].first][nnext[i][j].second] = board[i][j];
            board[i][j] = 0;
            q = true;
            break;
          }
        }
        if (q) break;
      }
      if (done) break;
      solve();
    }
    printf("%d\n", ((int)(ans).size()));
    for (int i = 0; i < int(((int)(ans).size())); i++)
      printf("%d %d %d\n", ans[i].i, ans[i].r, ans[i].c);
  }
}
