#include <bits/stdc++.h>
using namespace std;
const double DINF = numeric_limits<double>::infinity();
const long long MOD = 1e9 + 7;
const double EPS = 1e-7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long rnd(long long x, long long y) {
  static mt19937 mmtw(time(0));
  static uniform_int_distribution<long long> rd;
  return rd(mmtw) % (y - x + 1) + x;
}
struct item {
  int a, b, c;
};
int n, k;
int a[4][55];
int cnt = 0;
vector<item> res;
void park() {
  for (int i = 0; i < n; ++i) {
    if (a[1][i] == 0) continue;
    if (a[1][i] == a[0][i]) {
      res.push_back({a[1][i], 1, i + 1});
      a[1][i] = a[0][i] = 0;
      cnt--;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[2][i] == 0) continue;
    if (a[2][i] == a[3][i]) {
      res.push_back({a[2][i], 4, i + 1});
      a[2][i] = a[3][i] = 0;
      cnt--;
    }
  }
}
pair<int, int> nxt(int i, int j) {
  if (i == 1) {
    if (j == 0) {
      return {i + 1, j};
    } else {
      return {i, j - 1};
    }
  } else {
    if (j == n - 1) {
      return {i - 1, j};
    } else {
      return {i, j + 1};
    }
  }
}
void move() {
  vector<bool> used(k + 2, 0);
  for (int q = 0; q < 200; ++q) {
    for (int i = 1; i <= 2; ++i) {
      for (int j = 0; j < n; ++j) {
        if (a[i][j] == 0) continue;
        if (used[a[i][j]]) continue;
        auto t = nxt(i, j);
        int x = t.first;
        int y = t.second;
        if (a[x][y] == 0) {
          a[x][y] = a[i][j];
          a[i][j] = 0;
          used[a[x][y]] = true;
          res.push_back({a[x][y], x + 1, y + 1});
        }
      }
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
      if (i == 1 || i == 2) {
        if (a[i][j] != 0) cnt++;
      }
    }
  }
  park();
  if (cnt == n * 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n * 2 + 5; ++i) {
    move();
    park();
  }
  if (cnt != 0) {
    cout << -1 << endl;
  }
  cout << res.size() << endl;
  for (auto it : res) {
    cout << it.a << ' ' << it.b << ' ' << it.c << '\n';
  }
}
