#include <bits/stdc++.h>
using namespace std;
const int maxn = 60, maxans = 2e4;
int n, a[4][maxn], k, answer, cnt;
pair<int, pair<int, int> > ans[maxans];
void shift() {
  int i, j;
  for (int d1 = 1; d1 < 3; ++d1)
    for (int d2 = 0; d2 < n; ++d2)
      if (!a[d1][d2]) {
        i = d1;
        j = d2;
      }
  int lim = (n << 1) - 1;
  while (lim--)
    if (i == 2)
      if (!j) {
        if (a[i - 1][j]) ans[answer++] = {a[i - 1][j], {i, j}};
        swap(a[i][j], a[i - 1][j]);
        i--;
      } else {
        if (a[i][j - 1]) ans[answer++] = {a[i][j - 1], {i, j}};
        swap(a[i][j], a[i][j - 1]);
        j--;
      }
    else if (j == n - 1) {
      if (a[i + 1][j]) ans[answer++] = {a[i + 1][j], {i, j}};
      swap(a[i][j], a[i + 1][j]);
      i++;
    } else {
      if (a[i][j + 1]) ans[answer++] = {a[i][j + 1], {i, j}};
      swap(a[i][j], a[i][j + 1]);
      j++;
    }
  return;
}
int main() {
  cin >> n >> cnt;
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < n; ++j) cin >> a[i][j];
  bool f = true;
  for (int i = 1; i < 3; ++i)
    for (int j = 0; j < n; ++j)
      if (!a[i][j]) f = false;
  if (f) {
    for (int i = 0; i < n; ++i)
      if (a[1][i] && a[0][i] == a[1][i]) {
        ans[answer++] = {a[0][i], {0, i}};
        a[1][i] = 0;
        f = false;
        cnt--;
        break;
      }
    if (f) {
      for (int i = 0; i < n; ++i)
        if (a[2][i] && a[2][i] == a[3][i]) {
          ans[answer++] = {a[2][i], {3, i}};
          a[2][i] = 0;
          f = false;
          cnt--;
          break;
        }
      if (f) return cout << "-1\n", 0;
    }
  }
  while (cnt) {
    for (int i = 0; i < n; ++i) {
      if (a[1][i] && a[1][i] == a[0][i]) {
        ans[answer++] = {a[1][i], {0, i}};
        a[1][i] = 0;
        cnt--;
      }
      if (a[2][i] && a[2][i] == a[3][i]) {
        ans[answer++] = {a[2][i], {3, i}};
        a[2][i] = 0;
        cnt--;
      }
    }
    shift();
  }
  cout << answer << '\n';
  for (int i = 0; i < answer; ++i)
    cout << ans[i].first << ' ' << ans[i].second.first + 1 << ' '
         << ans[i].second.second + 1 << '\n';
  return 0;
}
