#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-9;
const double Exp = 2.718281828459045;
const double Pi = 3.1415926535897932;
const int Max_Bit = 63;
const int INF = 2000000000;
const long long LINF = 1000000000000000007ll;
const int MOD = 1000000007;
const int NMAX = 100005;
const int FMAX = 1005;
const int KMAX = 6;
int main() {
  int k, n, a[4][100];
  pair<int, int> o;
  o = make_pair(-1, -1);
  vector<pair<int, pair<int, int>>> ans;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int tmp = 0; tmp <= 2 * n; tmp++) {
    for (int i = 0; i < n; ++i) {
      if ((a[1][i] == a[0][i]) and (a[0][i])) {
        ans.push_back(make_pair(a[1][i], make_pair(1, i + 1)));
        a[1][i] = 0;
      }
      if ((a[2][i] == a[3][i]) and (a[3][i])) {
        ans.push_back(make_pair(a[2][i], make_pair(4, i + 1)));
        a[2][i] = 0;
      }
      if (a[1][i] == 0) o = make_pair(1, i);
      if (a[2][i] == 0) o = make_pair(2, i);
    }
    if (o.first < 0) {
      cout << -1 << endl;
      return 0;
    }
    int i = o.first, j = o.second;
    do {
      if ((i == 2) and (j == n - 1)) {
        if (a[1][j]) ans.push_back(make_pair(a[1][j], make_pair(i + 1, j + 1)));
        a[i][j] = a[1][j];
        i = 1;
      } else {
        if ((i == 1) and (j == 0)) {
          if (a[2][j])
            ans.push_back(make_pair(a[2][j], make_pair(i + 1, j + 1)));
          a[i][j] = a[2][j];
          i = 2;
        } else {
          if (i == 1) {
            if (a[i][j - 1])
              ans.push_back(make_pair(a[i][j - 1], make_pair(i + 1, j + 1)));
            a[i][j] = a[i][j - 1];
            j = j - 1;
          } else {
            if (a[i][j + 1])
              ans.push_back(make_pair(a[i][j + 1], make_pair(i + 1, j + 1)));
            a[i][j] = a[i][j + 1];
            j = j + 1;
          }
        }
      }
    } while ((i != o.first) or (j != o.second));
    if ((o.first == 1) and (o.second == n - 1)) {
      if (a[2][n - 1]) ans.pop_back();
      a[2][n - 1] = 0;
    } else if ((o.first == 2) and (o.second == 0)) {
      if (a[1][0]) ans.pop_back();
      a[1][0] = 0;
    } else if (o.first == 1) {
      if (a[1][o.second + 1]) ans.pop_back();
      a[1][o.second + 1] = 0;
    } else {
      if (a[2][o.second - 1]) ans.pop_back();
      a[2][o.second - 1] = 0;
    }
  }
  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;
  }
}
