#include <bits/stdc++.h>
using namespace std;
int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; }
int park[2][50];
int car[2][50];
struct ccc {
  int carid;
  int row;
  int column;
  ccc(int i, int r, int c) {
    carid = i;
    row = r;
    column = c;
  }
};
int n;
vector<ccc> ans;
void addans(int i, int r, int c) { ans.push_back(ccc(i, r + 1, c + 1)); }
void nextxy(int x, int y, int *nx, int *ny) {
  if (x == 0) {
    if (y == n - 1) {
      *nx = 1;
      *ny = n - 1;
    } else {
      *nx = 0;
      *ny = y + 1;
    }
  } else {
    if (y == 0) {
      *nx = 0;
      *ny = 0;
    } else {
      *nx = 1;
      *ny = y - 1;
    }
  }
}
int fucki(int i) { return i == 0 ? 0 : 3; }
void route() {
  int stx = 0, sty = 0;
  int nx = 0, ny = 0;
  while (car[stx][sty] != 0) {
    nextxy(stx, sty, &nx, &ny);
    stx = nx;
    sty = ny;
  }
  int mx, my;
  nextxy(nx, ny, &mx, &my);
  do {
    if (car[mx][my] != 0) {
      addans(car[mx][my], nx + 1, ny);
    }
    car[nx][ny] = car[mx][my];
    nx = mx;
    ny = my;
    nextxy(nx, ny, &mx, &my);
  } while (!(mx == stx && my == sty));
  car[nx][ny] = 0;
}
int main() {
  int m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", &park[0][i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &car[0][i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &car[1][i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &park[1][i]);
  }
  int carcnt = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) carcnt += car[i][j] != 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) {
      if (car[i][j] == 0) continue;
      if (car[i][j] == park[i][j]) {
        addans(car[i][j], fucki(i), j);
        car[i][j] = 0;
        park[i][j] = 0;
        carcnt--;
      }
    }
  if (carcnt == 2 * n) {
    cout << -1 << endl;
    return 0;
  }
  while (carcnt != 0) {
    route();
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < n; j++) {
        if (car[i][j] == 0) continue;
        if (car[i][j] == park[i][j]) {
          addans(car[i][j], fucki(i), j);
          car[i][j] = 0;
          carcnt--;
        }
      }
  }
  printf("%d\n", ans.size());
  for (auto item : ans) {
    printf("%d %d %d\n", item.carid, item.row, item.column);
  }
  return 0;
}
