#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[4][N];
bool solved[N];
int n;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
pair<int, int> p[4][N];
pair<int, int> emp(-1, -1);
vector<pair<int, int>> bfs(pair<int, int> s, pair<int, int> f,
                           pair<int, int> bad) {
  for (int c = 0; c < 4; c++)
    for (int i = 0; i < n; i++) p[c][i] = emp;
  queue<pair<int, int>> q;
  q.push(s);
  p[s.first][s.second] = s;
  while (!q.empty()) {
    pair<int, int> v = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      pair<int, int> u(v.first + dx[i], v.second + dy[i]);
      if (u.second < 0 || u.second >= n || u.first < 0 || u.first > 3) continue;
      if (u != f && (u.first == 0 || u.first == 3)) continue;
      if (u == bad) continue;
      if (p[u.first][u.second] != emp) continue;
      p[u.first][u.second] = v;
      q.push(u);
    }
  }
  vector<pair<int, int>> ans;
  if (p[f.first][f.second] == emp) return ans;
  while (true) {
    ans.push_back(f);
    if (s == f) break;
    f = p[f.first][f.second];
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
vector<pair<int, pair<int, int>>> ans;
void move(pair<int, int> s, pair<int, int> f) {
  int x = a[s.first][s.second];
  if (f.first != 0 && f.first != 3 && a[f.first][f.second] != 0) throw;
  if (x != 0) {
    ans.push_back(pair<int, pair<int, int>>(x, f));
    a[f.first][f.second] = x;
    a[s.first][s.second] = 0;
  }
}
pair<int, int> findCell(int val) {
  pair<int, int> res = emp;
  for (int c = 1; c <= 2; c++)
    for (int i = 0; i < n; i++)
      if (a[c][i] == val) res = pair<int, int>(c, i);
  return res;
}
void solve() {
  int k;
  cin >> n >> k;
  map<int, pair<int, int>> from, to;
  for (int c = 0; c < 4; c++) {
    for (int i = 0; i < n; i++) {
      cin >> a[c][i];
      if (a[c][i] == 0) continue;
      if (c == 0 || c == 3)
        to[a[c][i]] = pair<int, int>(c, i);
      else
        from[a[c][i]] = pair<int, int>(c, i);
    }
  }
  int rem = k;
  while (rem > 0) {
    bool ok = false;
    for (int car = 1; car <= k; car++) {
      if (solved[car]) continue;
      auto cur = findCell(car);
      auto path = bfs(cur, to[car], pair<int, int>(-1, -1));
      if (path.size() == 0) continue;
      if (path.size() == 2) {
        ok = true;
        move(path[0], path[1]);
        solved[car] = true;
        rem--;
        break;
      } else {
        pair<int, int> free = findCell(0);
        if (free == emp) continue;
        ok = true;
        for (int i = 1; i + 1 < path.size(); i++) {
          auto fe = bfs(free, path[i], path[i - 1]);
          for (int j = 1; j < fe.size(); j++) {
            move(fe[j], fe[j - 1]);
          }
          move(path[i - 1], path[i]);
          free = path[i - 1];
        }
        move(path[path.size() - 2], path[path.size() - 1]);
        solved[car] = true;
        rem--;
        break;
      }
    }
    if (!ok) {
      puts("-1");
      return;
    }
  }
  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.first << " " << x.second.first + 1 << " " << x.second.second + 1
         << endl;
  }
}
int main() {
  solve();
  (void)0;
  return 0;
}
