#include <bits/stdc++.h>
using namespace std;
int n, lol;
int arr[4][55];
queue<pair<int, pair<int, int> > > ans;
void masuk() {
  for (int j = 0; j < n; j++) {
    if (arr[1][j] == arr[0][j] && arr[1][j] > 0) {
      arr[1][j] = 0;
      ans.push(make_pair(arr[0][j], make_pair(0, j)));
      lol--;
    }
    if (arr[2][j] == arr[3][j] && arr[2][j] > 0) {
      arr[2][j] = 0;
      ans.push(make_pair(arr[3][j], make_pair(3, j)));
      lol--;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> lol;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> arr[i][j];
  vector<pair<int, int> > wey;
  for (int i = 0; i < n; i++) wey.push_back(make_pair(1, i));
  for (int i = n - 1; i >= 0; i--) wey.push_back(make_pair(2, i));
  for (int i = 0; i < n; i++) wey.push_back(make_pair(1, i));
  for (int i = n - 1; i >= 0; i--) wey.push_back(make_pair(2, i));
  wey.push_back(make_pair(1, 0));
  masuk();
  bool oof = true;
  for (int j = 0; j < n; j++)
    if (arr[1][j] == 0 || arr[2][j] == 0) oof = false;
  if (oof) {
    cout << "-1" << endl;
    return 0;
  }
  while (lol > 0) {
    masuk();
    if (lol == 0) break;
    for (int i = 1; i <= 2; i++)
      for (int j = 0; j < n; j++)
        if (arr[i][j] == 0) {
          int x;
          for (int k = 0; k < 2 * n; k++)
            if (wey[k] == make_pair(i, j)) x = k;
          for (int k = 0; k < 2 * n; k++) {
            masuk();
            if (lol == 0) break;
            int ax, ay, bx, by;
            ax = wey[x + k].first;
            ay = wey[x + k].second;
            bx = wey[x + k + 1].first;
            by = wey[x + k + 1].second;
            if (arr[bx][by] > 0) {
              ans.push(make_pair(arr[bx][by], make_pair(ax, ay)));
              arr[ax][ay] = arr[bx][by];
              arr[bx][by] = 0;
            }
          }
          break;
        }
  }
  cout << ans.size() << endl;
  while (!ans.empty()) {
    cout << ans.front().first << ' ' << ans.front().second.first + 1 << ' '
         << ans.front().second.second + 1 << endl;
    ans.pop();
  }
}
