#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, pair<int, int> > > ans;
  int v[4][n];
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> v[i][j];
    }
  }
  for (int i = 1; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      if (v[i][j] > 0) {
        int x = 0;
        if (i == 2) x = 3;
        if (v[x][j] == v[i][j]) {
          ans.push_back({v[i][j], {x + 1, j + 1}});
          v[i][j] = 0;
        }
      }
    }
  }
  int koln = 0;
  for (int i = 1; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      if (v[i][j] > 0) koln++;
    }
  }
  if (koln == 2 * n) {
    cout << -1;
    return 0;
  }
  int fl = 0;
  while (fl < koln) {
    for (int i = 1; i < 3; ++i) {
      for (int j = 0; j < n; ++j) {
        if (v[i][j] > 0) {
          if (i == 1) {
            if (j < n - 1) {
              if (v[i][j + 1] == 0) {
                swap(v[i][j], v[i][j + 1]);
                ans.push_back({v[i][j + 1], {i + 1, j + 2}});
              }
              if (v[0][j + 1] == v[i][j + 1]) {
                ans.push_back({v[i][j + 1], {1, j + 2}});
                v[i][j + 1] = 0;
                fl++;
              }
            } else if (v[2][j] == 0) {
              ans.push_back({v[i][j], {3, j + 1}});
              swap(v[i][j], v[2][j]);
              if (v[2][j] == v[3][j]) {
                ans.push_back({v[2][j], {4, j + 1}});
                v[2][j] = 0;
                fl++;
              }
            }
          } else {
            if (j > 0) {
              if (v[i][j - 1] == 0) {
                swap(v[i][j], v[i][j - 1]);
                ans.push_back({v[i][j - 1], {i + 1, j}});
              }
              if (v[3][j - 1] == v[i][j - 1]) {
                ans.push_back({v[i][j - 1], {4, j}});
                v[i][j - 1] = 0;
                fl++;
              }
            } else {
              if (v[1][j] == 0) {
                ans.push_back({v[i][j], {2, j + 1}});
                swap(v[1][j], v[i][j]);
              }
              if (v[1][j] == v[0][j]) {
                ans.push_back({v[1][j], {1, j + 1}});
                v[1][j] = 0;
                fl++;
              }
            }
          }
        }
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].first << " " << ans[i].second.first << " "
         << ans[i].second.second << endl;
  }
}
