#include <bits/stdc++.h>
using namespace std;
struct Operation {
  int i, r, c;
};
vector<Operation> l;
int n, k, mp[4][55], tot;
void transform(int &i, int &j) {
  if (i == 1 && j == n)
    i = 2;
  else if (i == 2 && j == 1)
    i = 1;
  else if (i == 1)
    j++;
  else
    j--;
}
int main() {
  ios::sync_with_stdio(false);
  int i, j, prei, prej;
  cin >> n >> k;
  for (i = 0; i < 4; i++)
    for (j = 1; j <= n; j++) cin >> mp[i][j];
  for (j = 1; j <= n; j++)
    if (mp[0][j] && mp[0][j] == mp[1][j]) {
      mp[1][j] = 0;
      l.push_back((Operation){mp[0][j], 0, j});
    }
  for (j = 1; j <= n; j++)
    if (mp[3][j] && mp[2][j] == mp[3][j]) {
      mp[2][j] = 0;
      l.push_back((Operation){mp[3][j], 3, j});
    }
  if (l.empty() && k == 2 * n) return cout << -1, 0;
  for (i = 1, j = 1, prei = 2, prej = 1; ++tot <= 100000;
       prei = i, prej = j, transform(i, j)) {
    if (mp[i][j]) {
      if (i == 1 && mp[1][j] == mp[0][j]) {
        mp[1][j] = 0;
        l.push_back((Operation){mp[0][j], 0, j});
      } else if (i == 2 && mp[2][j] == mp[3][j]) {
        mp[2][j] = 0;
        l.push_back((Operation){mp[3][j], 3, j});
      } else if (!mp[prei][prej]) {
        l.push_back((Operation){mp[i][j], prei, prej});
        mp[prei][prej] = mp[i][j];
        mp[i][j] = 0;
      }
    }
  }
  cout << (int)l.size() << endl;
  for (auto i : l) cout << i.i << ' ' << i.r + 1 << ' ' << i.c << endl;
  return 0;
}
