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