#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, a[4][51], i, j, p, q, empty = 0;
  vector<pair<long long, pair<long long, long long> > > ans;
  cin >> n >> k;
  for (i = 0; i < 4; i++)
    for (j = 0; j < n; j++) cin >> a[i][j];
  for (j = 0; j < n; j++)
    if (a[1][j] == a[0][j] and a[1][j] != 0)
      ans.push_back({a[1][j], {1, j + 1}}), a[1][j] = 0;
  for (j = 0; j < n; j++)
    if (a[2][j] == a[3][j] and a[2][j] != 0)
      ans.push_back({a[2][j], {4, j + 1}}), a[2][j] = 0;
  for (i = 1; i < 3; i++)
    for (j = 0; j < n; j++)
      if (a[i][j] == 0) empty++;
  if (empty == 0) {
    cout << -1;
    return (0);
  }
  while (empty < 2 * n) {
    pair<long long, long long> free_place, rot;
    for (i = 1; i < 3; i++)
      for (j = 0; j < n; j++)
        if (a[i][j] == 0) {
          free_place = {i, j};
          break;
        }
    rot = free_place;
    if (rot.first == 1) {
      while (rot.second + 1 < n) {
        if (a[rot.first][rot.second + 1] != 0) {
          ans.push_back(
              {a[rot.first][rot.second + 1], {rot.first + 1, rot.second + 1}});
        }
        a[rot.first][rot.second] = a[rot.first][rot.second + 1];
        rot.second++;
      }
      a[rot.first][rot.second] = a[rot.first + 1][rot.second];
      if (a[rot.first + 1][rot.second] != 0) {
        ans.push_back(
            {a[rot.first + 1][rot.second], {rot.first + 1, rot.second + 1}});
      }
      rot.first++;
      while (rot.second - 1 >= 0) {
        if (a[rot.first][rot.second - 1] != 0) {
          ans.push_back(
              {a[rot.first][rot.second - 1], {rot.first + 1, rot.second + 1}});
        }
        a[rot.first][rot.second] = a[rot.first][rot.second - 1];
        rot.second--;
      }
      rot.first--;
      if (free_place.second != 0) {
        a[rot.first + 1][rot.second] = a[rot.first][rot.second];
        if (a[rot.first][rot.second] != 0)
          ans.push_back(
              {a[rot.first][rot.second], {rot.first + 2, rot.second + 1}});
        while (rot.second + 1 < free_place.second) {
          a[rot.first][rot.second] = a[rot.first][rot.second + 1];
          if (a[rot.first][rot.second] != 0)
            ans.push_back(
                {a[rot.first][rot.second], {rot.first + 1, rot.second + 1}});
          rot.second++;
        }
        a[rot.first][rot.second] = 0;
      } else
        a[rot.first + 1][rot.second] = 0;
    } else {
      while (rot.second - 1 >= 0) {
        a[rot.first][rot.second] = a[rot.first][rot.second - 1];
        if (a[rot.first][rot.second] != 0)
          ans.push_back(
              {a[rot.first][rot.second], {rot.first + 1, rot.second + 1}});
        rot.second--;
      }
      a[rot.first][rot.second] = a[rot.first - 1][rot.second];
      if (a[rot.first][rot.second] != 0)
        ans.push_back(
            {a[rot.first][rot.second], {rot.first + 1, rot.second + 1}});
      rot.first--;
      while (rot.second + 1 < n) {
        if (a[rot.first][rot.second + 1] != 0) {
          ans.push_back(
              {a[rot.first][rot.second + 1], {rot.first + 1, rot.second + 1}});
        }
        a[rot.first][rot.second] = a[rot.first][rot.second + 1];
        rot.second++;
      }
      if (free_place.second != n - 1) {
        a[rot.first][rot.second] = a[rot.first + 1][rot.second];
        if (a[rot.first + 1][rot.second] != 0)
          ans.push_back(
              {a[rot.first + 1][rot.second], {rot.first + 1, rot.second + 1}});
        rot.first++;
        while (rot.second - 1 > free_place.second) {
          a[rot.first][rot.second] = a[rot.first][rot.second - 1];
          if (a[rot.first][rot.second] != 0)
            ans.push_back(
                {a[rot.first][rot.second], {rot.first + 1, rot.second + 1}});
          rot.second--;
        }
        a[rot.first][rot.second] = 0;
      } else
        a[rot.first][rot.second] = 0;
    }
    for (j = 0; j < n; j++)
      if (a[1][j] == a[0][j] and a[1][j] != 0)
        ans.push_back({a[1][j], {1, j + 1}}), a[1][j] = 0;
    for (j = 0; j < n; j++)
      if (a[2][j] == a[3][j] and a[2][j] != 0)
        ans.push_back({a[2][j], {4, j + 1}}), a[2][j] = 0;
    empty = 0;
    for (i = 1; i < 3; i++)
      for (j = 0; j < n; j++)
        if (a[i][j] == 0) empty++;
  }
  cout << ans.size() << endl;
  for (auto x : ans)
    cout << x.first << " " << x.second.first << " " << x.second.second << endl;
}
