#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 30;
const int N = 111;
vector<pair<int, pair<int, int>>> ans;
int n = 4, m, k;
int a[11][N];
bool _1 = 1;
bool check() {
  bool f = 0;
  for (int j = 0; j < m; j++) {
    if (a[1][j] == a[0][j] && a[0][j]) {
      ans.push_back({a[1][j], {1, j + 1}});
      a[1][j] = 0;
      _1 = 0;
    }
    if (a[2][j] == a[3][j] && a[3][j]) {
      ans.push_back({a[2][j], {4, j + 1}});
      a[2][j] = 0;
      _1 = 0;
    }
    if (a[1][j] || a[2][j]) f = 1;
  }
  return f;
}
bool r() {
  for (int j = 0; j < m - 1; j++) {
    if (a[1][j + 1] == 0 && a[1][j]) {
      ans.push_back({a[1][j], {2, j + 2}});
      a[1][j + 1] = a[1][j];
      a[1][j] = 0;
      check();
    }
  }
  if (a[2][m - 1] == 0 && a[1][m - 1]) {
    ans.push_back({a[1][m - 1], {3, m}});
    a[2][m - 1] = a[1][m - 1];
    a[1][m - 1] = 0;
    check();
  }
  for (int j = 1; j < m; j++) {
    if (a[2][j - 1] == 0 && a[2][j]) {
      ans.push_back({a[2][j], {3, j}});
      a[2][j - 1] = a[2][j];
      a[2][j] = 0;
      check();
    }
  }
  if (a[1][0] == 0 && a[2][0]) {
    ans.push_back({a[2][0], {2, 1}});
    a[1][0] = a[2][0];
    a[2][0] = 0;
    check();
  }
  return check();
}
int main() {
  scanf("%d%d", &m, &k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  check();
  if (_1 && k == 2 * m) {
    printf("-1");
    return 0;
  }
  while (r())
    ;
  printf("%d\n", ans.size());
  for (auto x : ans)
    printf("%d %d %d\n", x.first, x.second.first, x.second.second);
  return 0;
}
