#include <bits/stdc++.h>
using namespace std;
const int di[] = {0, 0, 1, -1};
const int dj[] = {1, -1, 0, 0};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long double EPS = 1e-6;
int n, k;
inline pair<int, int> getNxt(pair<int, int> cur) {
  if (cur.first == 1) {
    if (cur.second == n - 1)
      cur.first = 2;
    else
      cur.second++;
  } else {
    if (cur.second == 0)
      cur.first = 1;
    else
      cur.second--;
  }
  return cur;
}
inline pair<int, int> getPrv(pair<int, int> cur) {
  if (cur.first == 1) {
    if (cur.second == 0)
      cur.first = 2;
    else
      cur.second--;
  } else {
    if (cur.second == n - 1)
      cur.first = 1;
    else
      cur.second++;
  }
  return cur;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;
  vector<vector<int>> g(4, vector<int>(n));
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> g[i][j];
    }
  }
  int done = 0, cnt = 0;
  vector<pair<int, pair<int, int>>> r;
  pair<int, int> cur(1, 0);
  while (done < k) {
    if (cnt > 3 * 2 * n) {
      cout << -1 << endl;
      return 0;
    }
    pair<int, int> prv = getPrv(cur);
    if (g[cur.first][cur.second]) {
      if (cur.first == 1 &&
          g[cur.first - 1][cur.second] == g[cur.first][cur.second]) {
        r.emplace_back(g[cur.first][cur.second],
                       pair<int, int>(cur.first - 1, cur.second));
        g[cur.first][cur.second] = 0;
        done++;
        cnt = 0;
      } else if (cur.first == 2 &&
                 g[cur.first + 1][cur.second] == g[cur.first][cur.second]) {
        r.emplace_back(g[cur.first][cur.second],
                       pair<int, int>(cur.first + 1, cur.second));
        g[cur.first][cur.second] = 0;
        done++;
        cnt = 0;
      } else if (g[prv.first][prv.second] == 0) {
        r.emplace_back(g[cur.first][cur.second], prv);
        swap(g[cur.first][cur.second], g[prv.first][prv.second]);
        cnt = 0;
      } else
        cnt++;
    }
    cur = getNxt(cur);
  }
  cout << r.size() << endl;
  for (auto& i : r) {
    cout << i.first << " " << i.second.first + 1 << " " << i.second.second + 1
         << endl;
  }
  cin.ignore(), cin.get();
}
