#include <bits/stdc++.h>
using namespace std;
int park[5][100];
bool vis[5][100];
int n, k, cnt;
vector<int> ANS[6];
void add(int a, int b, int c) {
  ANS[1].push_back(a);
  ANS[2].push_back(b);
  ANS[3].push_back(c);
}
void plot() {
  for (int i = 1; i <= n; i++) {
    if (park[2][i] && park[1][i] == park[2][i]) {
      add(park[2][i], 1, i);
      park[2][i] = 0;
      cnt++;
    }
    if (park[3][i] && park[3][i] == park[4][i]) {
      add(park[3][i], 4, i);
      park[3][i] = 0;
      cnt++;
    }
  }
}
bool judge() {
  bool flag = false;
  for (int i = 1; i <= n; i++)
    if (!park[2][i] || !park[3][i]) flag = true;
  if (!flag) return false;
  return true;
}
pair<int, int> counterclockwise(pair<int, int> u) {
  if (u.first == 2) {
    if (u.second == 1)
      return make_pair(3, 1);
    else
      return make_pair(2, u.second - 1);
  } else {
    if (u.second == n)
      return make_pair(2, n);
    else
      return make_pair(3, u.second + 1);
  }
}
pair<int, int> clockwise(pair<int, int> u) {
  if (u.first == 2) {
    if (u.second == n)
      return make_pair(3, n);
    else
      return make_pair(2, u.second + 1);
  } else {
    if (u.second == 1)
      return make_pair(2, 1);
    else
      return make_pair(3, u.second - 1);
  }
}
void carmove() {
  pair<int, int> now = make_pair(3, n);
  int limit = 500;
  while (limit--) {
    pair<int, int> nxt = counterclockwise(now);
    if (!park[nxt.first][nxt.second]) {
      now = nxt;
      break;
    }
    now = nxt;
  }
  int tcnt = 0;
  while (tcnt < 2 * n - 1) {
    tcnt++;
    pair<int, int> nxt = clockwise(now);
    if (park[nxt.first][nxt.second]) {
      add(park[nxt.first][nxt.second], now.first, now.second);
      park[now.first][now.second] = park[nxt.first][nxt.second];
      park[nxt.first][nxt.second] = 0;
    }
    now = nxt;
  }
  return;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) {
      int tmp;
      scanf("%d", &tmp);
      park[i][j] = tmp;
    }
  plot();
  if (!judge()) {
    puts("-1");
    return 0;
  }
  while (cnt < k) {
    memset(vis, 0, sizeof(vis));
    carmove();
    plot();
  }
  printf("%d\n", ANS[1].size());
  for (int i = 0; i < ANS[1].size(); i++)
    printf("%d %d %d\n", ANS[1][i], ANS[2][i], ANS[3][i]);
}
