#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point() {}
  Point(int _x, int _y) : x(_x), y(_y) {}
} np[5][55];
struct Ans {
  int num;
  Point p;
  Ans() {}
  Ans(int _num, Point _p) : num(_num), p(_p) {}
};
vector<Ans> ans;
int M[5][55];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> M[i][j];
    }
  }
  for (int i = 1; i < n; i++) np[2][i] = Point(2, i + 1);
  np[2][n] = Point(3, n);
  for (int i = 2; i <= n; i++) np[3][i] = Point(3, i - 1);
  np[3][1] = Point(2, 1);
  for (int re = 0; re < 205; re++) {
    bool found = 0;
    for (int i = 2; i <= 3; i++) {
      for (int j = 1; j <= n; j++) {
        if (M[i][j] > 0 && M[i][j] == M[((i - 1) ^ 1) + 1][j]) {
          ans.push_back(Ans(M[i][j], Point(((i - 1) ^ 1) + 1, j)));
          M[i][j] = 0;
          found = 1;
        }
      }
    }
    int mv = 1;
    for (int i = 1; i <= n; i++) {
      Point p = np[3][i];
      int nx = p.x, ny = p.y;
      if (M[3][i] > 0 && M[nx][ny] == 0) {
        ans.push_back(Ans(M[3][i], Point(nx, ny)));
        swap(M[3][i], M[nx][ny]);
        if (i == 1) mv = 2;
        found = 1;
      }
    }
    for (int i = n; i >= mv; i--) {
      Point p = np[2][i];
      int nx = p.x, ny = p.y;
      if (M[2][i] > 0 && M[nx][ny] == 0) {
        ans.push_back(Ans(M[2][i], Point(nx, ny)));
        swap(M[2][i], M[nx][ny]);
        found = 1;
      }
    }
    if (!found) break;
  }
  bool bad = 0;
  for (int i = 2; i <= 3; i++) {
    for (int j = 1; j <= n; j++) {
      if (M[i][j]) {
        bad = 1;
        break;
      }
    }
  }
  if (bad) {
    cout << -1;
    return 0;
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].num << " " << ans[i].p.x << " " << ans[i].p.y << "\n";
  return 0;
}
