#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
const int N = 55;
int n, k;
int a[4][N];
bool read() {
  if (!(cin >> n >> k)) return false;
  for (int i = 0; i < int(4); ++i)
    for (int j = 0; j < int(n); ++j) cin >> a[i][j];
  return true;
}
int cnt;
bool mov;
vector<pair<int, pair<int, int>>> ans;
void check(int first, int second) {
  if (first == 1) {
    if (a[first][second] != 0 && a[first][second] == a[first - 1][second]) {
      mov = true;
      ans.push_back(make_pair(a[first][second], make_pair(first, second + 1)));
      a[first][second] = 0;
      --cnt;
    }
  } else {
    if (a[first][second] != 0 && a[first][second] == a[first + 1][second]) {
      mov = true;
      ans.push_back(
          make_pair(a[first][second], make_pair(first + 2, second + 1)));
      a[first][second] = 0;
      --cnt;
    }
  }
}
void solve() {
  cnt = k;
  while (cnt > 0 && int((ans).size()) < 20000) {
    mov = false;
    for (int i = 0; i < int(n); ++i) {
      check(1, i);
      check(2, i);
    }
    for (int i = 0; i < int(n - 1); ++i) {
      if (a[1][i] != 0 && a[1][i + 1] == 0) {
        mov = true;
        ans.push_back(make_pair(a[1][i], make_pair(2, i + 2)));
        a[1][i + 1] = a[1][i];
        a[1][i] = 0;
        check(1, i + 1);
      }
    }
    for (int i = n - 1; i > 0; --i) {
      if (a[2][i] != 0 && a[2][i - 1] == 0) {
        mov = true;
        ans.push_back(make_pair(a[2][i], make_pair(3, i)));
        a[2][i - 1] = a[2][i];
        a[2][i] = 0;
        check(2, i - 1);
      }
    }
    if (a[2][0] != 0 && a[1][0] == 0) {
      mov = true;
      ans.push_back(make_pair(a[2][0], make_pair(2, 1)));
      a[1][0] = a[2][0];
      a[2][0] = 0;
      check(1, 0);
    }
    if (a[1][n - 1] != 0 && a[2][n - 1] == 0) {
      mov = true;
      ans.push_back(make_pair(a[1][n - 1], make_pair(3, n)));
      a[2][n - 1] = a[1][n - 1];
      a[1][n - 1] = 0;
      check(2, n - 1);
    }
    if (!mov) {
      cout << -1 << endl;
      return;
    }
  }
  if (int((ans).size()) == 20000) {
    cout << -1 << endl;
  } else {
    cout << int((ans).size()) << endl;
    for (auto it : ans)
      cout << it.first << " " << it.second.first << " " << it.second.second
           << endl;
  }
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  while (read()) {
    solve();
  }
}
