#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long inf64 = (long long)inf * inf;
int n, k;
int a[10][100];
struct Step {
  int car;
  int x, y;
};
vector<Step> ans;
void calcnextmovepos(int x, int y, int& nextx, int& nexty) {
  if (x == 2) {
    if (y == 1) {
      nextx = 3;
      nexty = 1;
    } else {
      nextx = x;
      nexty = y - 1;
    }
  } else {
    if (y == n) {
      nextx = 2;
      nexty = n;
    } else {
      nextx = x;
      nexty = y + 1;
    }
  }
}
void moveto(int x, int y, int tox, int toy) {
  Step astep;
  astep.car = a[x][y];
  astep.x = tox;
  astep.y = toy;
  ans.push_back(astep);
  a[tox][toy] = a[x][y];
  a[x][y] = 0;
}
int main() {
  while (cin >> n >> k) {
    ans.clear();
    for (int i = 1; i <= 4; i++) {
      for (int j = 1; j <= n; j++) {
        cin >> a[i][j];
      }
    }
    int car = k;
    while (car > 0) {
      bool ismove = false;
      for (int i = 1; i <= n; i++) {
        if (a[2][i] == 0) {
          continue;
        }
        if (a[2][i] == a[1][i]) {
          car--;
          moveto(2, i, 1, i);
          ismove = true;
          continue;
        }
        int nextx = 0, nexty = 0;
        calcnextmovepos(2, i, nextx, nexty);
        if (a[nextx][nexty] != 0) {
          continue;
        }
        moveto(2, i, nextx, nexty);
        ismove = true;
      }
      for (int i = n; i >= 1; i--) {
        if (a[3][i] == 0) {
          continue;
        }
        if (a[3][i] == a[4][i]) {
          car--;
          moveto(3, i, 4, i);
          ismove = true;
          continue;
        }
        int nextx = 0, nexty = 0;
        calcnextmovepos(3, i, nextx, nexty);
        if (a[nextx][nexty] != 0) {
          continue;
        }
        moveto(3, i, nextx, nexty);
        ismove = true;
      }
      if (!ismove) {
        break;
      }
    }
    if (car > 0) {
      cout << -1 << endl;
      continue;
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i].car << " " << ans[i].x << " " << ans[i].y << endl;
    }
  }
  return 0;
}
