#include <bits/stdc++.h>
using namespace std;
int mas[6][52];
struct op {
  int m, i, j;
  op(int m = 0, int i = 0, int j = 0) : m(m), i(i), j(j) {}
};
void print(vector<op> v) {
  cout << v.size() << endl;
  for (auto it : v) {
    cout << it.m << ' ' << it.i << ' ' << it.j << endl;
  }
  exit(0);
}
int n;
pair<int, int> gor(pair<int, int> pos) {
  if (pos.first == 2) {
    if (pos.second != n) {
      return {pos.first, pos.second + 1};
    } else {
      return {pos.first + 1, pos.second};
    }
  } else {
    if (pos.second != 1) {
      return {pos.first, pos.second - 1};
    } else {
      return {pos.first - 1, pos.second};
    }
  }
}
pair<int, int> gol(pair<int, int> pos) {
  if (pos.first == 2) {
    if (pos.second != 1) {
      return {pos.first, pos.second - 1};
    } else {
      return {pos.first + 1, pos.second};
    }
  } else {
    if (pos.second != n) {
      return {pos.first, pos.second + 1};
    } else {
      return {pos.first - 1, pos.second};
    }
  }
}
signed main() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= 4; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> mas[i][j];
    }
  }
  vector<op> ans;
  int gg = 0;
  if (m == 2 * n) {
    for (int j = 1; j <= n; ++j) {
      if (mas[2][j] == mas[1][j]) {
        ans.push_back(op(mas[2][j], 1, j));
        mas[2][j] = 0;
        ++gg;
      }
      if (mas[3][j] == mas[4][j]) {
        ans.push_back(op(mas[3][j], 4, j));
        mas[3][j] = 0;
        ++gg;
      }
    }
    if (ans.size() == 0) {
      return 0 * printf("-1");
    }
  }
  while (gg != m) {
    pair<int, int> pos = {0, 0};
    for (int i = 2; i <= 3; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (!mas[i][j]) {
          pos = {i, j};
          goto ll;
        }
      }
    }
  ll:;
    int cnt = 0;
    while (cnt + gg != m) {
      while (!mas[pos.first][pos.second]) {
        pos = gol(pos);
      }
      ++cnt;
      pair<int, int> to = gor(pos);
      ans.push_back(op(mas[pos.first][pos.second], to.first, to.second));
      swap(mas[pos.first][pos.second], mas[to.first][to.second]);
    }
    for (int j = 1; j <= n; ++j) {
      if (mas[2][j] == mas[1][j] && mas[2][j]) {
        ans.push_back(op(mas[2][j], 1, j));
        mas[2][j] = 0;
        ++gg;
      }
      if (mas[3][j] == mas[4][j] && mas[3][j]) {
        ans.push_back(op(mas[3][j], 4, j));
        mas[3][j] = 0;
        ++gg;
      }
    }
  }
  assert(ans.size() <= 20000);
  print(ans);
}
