#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
int A[5][MAXN];
int N, K;
int main() {
  cin >> N >> K;
  vector<vector<int> > ans;
  for (int i = 1; i <= 4; ++i) {
    for (int j = 1; j <= N; ++j) {
      cin >> A[i][j];
    }
  }
  bool flag = true;
  while (flag) {
    flag = false;
    for (int i = 1; i <= N; ++i) {
      if (!flag && A[2][i] && A[2][i] == A[1][i]) {
        flag = true;
        A[2][i] = 0;
        ans.push_back({A[1][i], 1, i});
      }
      if (!flag && A[3][i] && A[4][i] == A[3][i]) {
        flag = true;
        A[3][i] = 0;
        ans.push_back({A[4][i], 4, i});
      }
    }
    for (int i = 2; i <= 3; ++i) {
      for (int j = 1; j <= N; ++j) {
        if (flag) {
          continue;
        }
        int nj = j, ni = i;
        if (i == 2) {
          if (nj == N) {
            ni = 3;
          } else {
            ++nj;
          }
        } else {
          if (nj == 1) {
            ni = 2;
          } else {
            --nj;
          }
        }
        if (A[i][j] && !A[ni][nj]) {
          swap(A[i][j], A[ni][nj]);
          ans.push_back({A[ni][nj], ni, nj});
          flag = true;
        }
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    if (A[2][i] || A[3][i]) {
      cout << "-1";
      return 0;
    }
  }
  cout << ans.size() << "\n";
  for (auto& an : ans) {
    for (int x : an) {
      cout << x << " ";
    }
    cout << "\n";
  }
}
