#include <bits/stdc++.h>
using namespace std;
const int n = 52;
int G[2][n], C[2][n];
int N, K;
vector<tuple<int, int, int>> res;
pair<int, int> empty = {-1, -1};
void moveC(int y, int x, int d) {
  int i = C[y][x];
  C[y][x] = 0;
  pair<int, int> oldC = {y, x};
  if (d == 0) {
    y--;
  } else if (d == 1) {
    y++;
  } else if (d == 2) {
    x--;
  } else {
    x++;
  }
  if (y >= 0 && y <= 1)
    C[y][x] = i;
  else {
    empty = oldC;
    K--;
  }
  y += 2;
  x++;
  res.push_back(make_tuple(i, y, x));
}
void movePerfect() {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 2; ++j) {
      if (C[j][i] != 0 && C[j][i] == G[j][i]) {
        if (j == 0)
          moveC(j, i, 0);
        else
          moveC(j, i, 1);
      }
      if (C[j][i] == 0) empty = {j, i};
    }
  }
}
pair<int, int> nextP(pair<int, int> pos) {
  int x, y;
  tie(y, x) = pos;
  if (y == 0) {
    if (x == N - 1) {
      y = 1;
    } else
      x++;
  } else {
    if (x == 0)
      y = 0;
    else
      x--;
  }
  pair<int, int> newP = {y, x};
  return newP;
}
void moveNextP(pair<int, int> pos) {
  int x, y, yN, xN;
  tie(y, x) = pos;
  tie(yN, xN) = nextP(pos);
  if (C[yN][xN] == 0) return;
  if (y == 0) {
    if (x == N - 1) {
      moveC(yN, xN, 0);
    } else
      moveC(yN, xN, 2);
  } else {
    if (x == 0)
      moveC(yN, xN, 1);
    else
      moveC(yN, xN, 3);
  }
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> G[0][i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> C[0][i];
    if (C[0][i] == 0) empty = {0, i};
  }
  for (int i = 0; i < N; ++i) {
    cin >> C[1][i];
    if (C[1][i] == 0) empty = {1, i};
  }
  for (int i = 0; i < N; ++i) {
    cin >> G[1][i];
  }
  movePerfect();
  if (empty.first == -1) {
    cout << -1 << endl;
    return 0;
  }
  while (K > 0) {
    pair<int, int> pos = empty;
    while (nextP(pos) != empty) {
      moveNextP(pos);
      pos = nextP(pos);
    }
    movePerfect();
  }
  cout << res.size() << endl;
  for (auto t : res)
    cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
  return 0;
}
