#include <bits/stdc++.h>
using namespace std;
int a[4][100];
int b[200];
int c[2][200];
struct p {
  int x, y, z;
} sum;
vector<p> ans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) b[i] = a[0][i], c[0][i] = a[1][i];
  for (int i = 0; i < n; i++)
    b[2 * n - i - 1] = a[3][i], c[0][2 * n - i - 1] = a[2][i];
  int r = m;
  while (m) {
    for (int i = 0; i < 2 * n; i++)
      if (b[i] == c[0][i] && b[i] != 0) {
        sum.x = b[i];
        if (i < n)
          sum.y = 1, sum.z = i + 1;
        else
          sum.y = 4, sum.z = 2 * n - i;
        ans.push_back(sum);
        m--;
        c[0][i] = 0;
      }
    if (m == 2 * n) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 1; i < 2 * n; i++) c[1][i] = c[0][i - 1];
    c[1][0] = c[0][2 * n - 1];
    int h = -1;
    for (int i = 0; i < 2 * n; i++)
      if (c[0][i] == 0) {
        h = i;
        break;
      }
    for (int j = h; j > h - 2 * n; j--) {
      int i = (j + 2 * n) % (2 * n);
      c[0][i] = c[1][i];
      if (c[0][i] != 0) {
        sum.x = c[0][i];
        if (i < n)
          sum.y = 2, sum.z = i + 1;
        else
          sum.y = 3, sum.z = 2 * n - i;
        ans.push_back(sum);
      }
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d %d\n", ans[i].x, ans[i].y, ans[i].z);
}
