#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
vector<pair<int, pair<int, int> > > mv;
long long a[5][51] = {0}, n, k;
pair<int, int> dest[101];
pair<int, int> init[101];
vector<int> parked(101);
void show() {
  cout << endl;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
void mkmv(int x, int y, int r, int c) {
  mv.push_back(make_pair(a[x][y], make_pair(r, c)));
  a[r][c] = a[x][y];
  a[x][y] = 0;
}
void mksp(int r, int c, int v) {
  if (a[r][c] == 0) return;
  int x = 1, y = 2;
  for (int i = 1; i <= n; i++) {
    if (a[2][i] == 0) {
      x = 2;
      y = i;
      break;
    }
    if (a[3][i] == 0) {
      x = 3;
      y = i;
      break;
    }
  }
  int d = 1, xa = 2;
  if (x == 2) xa = 3;
  if (c < y) d = -1;
  while (y != c) {
    if (a[x][y + d] != v && a[x][y + d]) {
      mkmv(x, y + d, x, y);
      y += d;
    } else if (a[x][y + d] == v) {
      if (a[xa][y]) mkmv(xa, y, x, y);
      x = 2 + (x + 1) % 2;
      xa = 2 + (x + 1) % 2;
    } else
      y += d;
  }
  if (x != r && a[r][c]) mkmv(r, c, x, y);
}
void park(int v) {
  int y = init[v].second, c = dest[v].second, x = init[v].first,
      r = dest[v].first;
  for (int j = 1; j <= n; j++) {
    if (a[2][j] == v) {
      x = 2;
      y = j;
      break;
    }
    if (a[3][j] == v) {
      x = 3;
      y = j;
      break;
    }
  }
  int d = 1;
  if (c < y) d = -1;
  while (y != c) {
    mksp(x, y + d, v);
    mkmv(x, y, x, y + d);
    y += d;
  }
  if (abs(r - x) == 2) {
    mksp(2 + (x + 1) % 2, y, v);
    mkmv(x, y, 2 + (x + 1) % 2, y);
    x = 2 + (x + 1) % 2;
  }
  mkmv(x, y, r, c);
}
int main() {
  long long x, y, z, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if ((i == 1 || i == 4) && a[i][j]) {
        dest[a[i][j]] = make_pair(i, j);
      } else if ((i == 2 || i == 3) && a[i][j]) {
        init[a[i][j]] = make_pair(i, j);
      }
    }
  }
  long long nocl = k;
  for (int i = 1; i <= n; i++) {
    if (a[1][i] && a[1][i] == a[2][i]) {
      mv.push_back(make_pair(a[2][i], make_pair(1, i)));
      a[2][i] = 0;
      nocl--;
      parked[a[1][i]]++;
    }
    if (a[4][i] && a[4][i] == a[3][i]) {
      mv.push_back(make_pair(a[3][i], make_pair(4, i)));
      a[3][i] = 0;
      nocl--;
      parked[a[4][i]]++;
    }
  }
  if (nocl == 2 * n) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    if (parked[i] == 0) park(i);
  }
  cout << mv.size() << endl;
  for (int i = 0; i < mv.size(); i++) {
    cout << mv[i].first << " " << mv[i].second.first << " "
         << mv[i].second.second << endl;
  }
  return 0;
}
