#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 1e2 + 5;
int a[maxn][maxn];
char s[maxn];
int num, step;
vector<int> p[20005];
int n, k;
void init() {
  for (int i = 0; i < 20003; i++) p[i].clear();
}
void fix() {
  for (int i = 1; i <= n; i++) {
    if (a[1][i] == a[2][i] && a[1][i] != 0) {
      p[step].push_back(a[1][i]);
      p[step].push_back(1);
      p[step].push_back(i);
      step++;
      num--;
      a[1][i] = a[2][i] = 0;
    }
    if (a[3][i] == a[4][i] && a[4][i] != 0) {
      p[step].push_back(a[4][i]);
      p[step].push_back(4);
      p[step].push_back(i);
      step++;
      num--;
      a[3][i] = a[4][i] = 0;
    }
  }
}
int ndx, ndy;
void zhuan() {
  for (int i = 2; i <= 3; i++) {
    int have = 0;
    for (int j = 1; j <= n; j++)
      if (a[i][j] == 0) {
        ndx = i;
        ndy = j;
        have = 1;
        break;
      }
    if (have) break;
  }
  if (ndx == 2) {
    for (int i = ndy + 1; i <= n; i++) {
      a[2][i - 1] = a[2][i];
      if (a[2][i] != 0) {
        p[step].push_back(a[2][i]);
        p[step].push_back(2);
        p[step].push_back(i - 1);
        step++;
      }
    }
    a[2][n] = a[3][n];
    if (a[3][n] != 0) {
      p[step].push_back(a[3][n]);
      p[step].push_back(2);
      p[step].push_back(n);
      step++;
    }
    for (int i = n; i > 0; i--) {
      a[3][i] = a[3][i - 1];
      if (a[3][i - 1] != 0) {
        p[step].push_back(a[3][i - 1]);
        p[step].push_back(3);
        p[step].push_back(i);
        step++;
      }
    }
    a[3][1] = a[2][1];
    if (a[2][1] != 0 && ndy != 1) {
      p[step].push_back(a[2][1]);
      p[step].push_back(3);
      p[step].push_back(1);
      step++;
    }
    for (int i = 2; i < ndy; i++) {
      a[2][i - 1] = a[2][i];
      if (a[2][i] != 0) {
        p[step].push_back(a[2][i]);
        p[step].push_back(2);
        p[step].push_back(i - 1);
        step++;
      }
    }
    if (ndy == 1) {
      a[3][1] = 0;
    } else
      a[2][ndy - 1] = 0;
  } else if (ndx == 3) {
    for (int i = ndy - 1; i >= 0; i--) {
      a[3][i + 1] = a[3][i];
      if (a[3][i] != 0) {
        p[step].push_back(a[3][i]);
        p[step].push_back(3);
        p[step].push_back(i + 1);
        step++;
      }
    }
    a[3][1] = a[2][1];
    if (a[2][1] != 0) {
      p[step].push_back(a[2][1]);
      p[step].push_back(3);
      p[step].push_back(1);
      step++;
    }
    for (int i = 1; i < n; i++) {
      a[2][i] = a[2][i + 1];
      if (a[2][i + 1] != 0) {
        p[step].push_back(a[2][i + 1]);
        p[step].push_back(2);
        p[step].push_back(i);
        step++;
      }
    }
    a[2][n] = a[3][n];
    if (a[3][n] != 0 && ndy != n) {
      p[step].push_back(a[3][n]);
      p[step].push_back(2);
      p[step].push_back(n);
      step++;
    }
    for (int i = n; i > ndy + 1; i--) {
      a[3][i] = a[3][i - 1];
      if (a[3][i - 1] != 0) {
        p[step].push_back(a[3][i - 1]);
        p[step].push_back(3);
        p[step].push_back(i);
        step++;
      }
    }
    if (ndy == n) {
      a[2][n] = 0;
    } else
      a[3][ndy + 1] = 0;
  }
}
int main() {
  while (cin >> n >> k) {
    init();
    for (int i = 1; i <= 4; i++)
      for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
    int have = 0;
    for (int j = 1; j <= n; j++) {
      if (a[1][j] == a[2][j] || a[3][j] == a[4][j]) {
        have = 1;
        break;
      }
    }
    if (!have && k == 2 * n) {
      cout << "-1" << endl;
      continue;
    }
    step = 0;
    num = k;
    while (num != 0) {
      fix();
      zhuan();
    }
    cout << step << endl;
    for (int i = 0; i < step; i++)
      printf("%d %d %d\n", p[i][0], p[i][1], p[i][2]);
  }
}
