#include <bits/stdc++.h>
using namespace std;
const int N = 55;
struct data {
  int car, row, col;
  data(int car = 0, int row = 0, int col = 0) : car(car), row(row), col(col) {}
};
int n, k, a[5][N];
vector<data> ans;
bool used[5][N], canDo = true;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  while (canDo) {
    canDo = false;
    memset(used, 0, sizeof(used));
    pair<int, int> head = {-1, -1};
    for (int i = 2; i <= 3; i++) {
      for (int j = 1; j <= n; j++) {
        if (i == 2) {
          if (a[i - 1][j] == a[i][j] && a[i][j]) {
            ans.push_back(data(a[i][j], i - 1, j));
            swap(a[i - 1][j], a[i][j]);
            a[i][j] = 0;
          }
        } else {
          if (a[i + 1][j] == a[i][j] && a[i][j]) {
            ans.push_back(data(a[i][j], i + 1, j));
            swap(a[i + 1][j], a[i][j]);
            a[i][j] = 0;
          }
        }
      }
    }
    for (int i = 2; i <= 3; i++) {
      for (int j = 1; j <= n; j++) {
        if (i == 2) {
          if (j == 1) {
            if (a[i + 1][j] == 0) {
              head = {i, j};
              break;
            }
          } else {
            if (a[i][j - 1] == 0) {
              head = {i, j};
              break;
            }
          }
        } else {
          if (j == n) {
            if (a[i - 1][j] == 0) {
              head = {i, j};
              break;
            }
          } else {
            if (a[i][j + 1] == 0) {
              head = {i, j};
              break;
            }
          }
        }
      }
      if (head.first != -1) break;
    }
    if (head.first == -1) return !printf("%d", -1);
    if (head.first == 2) {
      int i = 2;
      for (int j = head.second; j <= n; j++) {
        if (!a[i][j]) continue;
        if (a[i - 1][j] == a[i][j]) {
          ans.push_back(data(a[i][j], i - 1, j));
          swap(a[i - 1][j], a[i][j]);
          a[i][j] = 0;
        } else {
          if (j > 1) {
            ans.push_back(data(a[i][j], i, j - 1));
            swap(a[i][j], a[i][j - 1]);
          } else {
            ans.push_back(data(a[i][j], i + 1, j));
            swap(a[i][j], a[i + 1][j]);
            used[i + 1][j] = true;
          }
        }
      }
      i = 3;
      for (int j = n; j >= 1; j--) {
        if (used[i][j]) continue;
        if (!a[i][j]) continue;
        if (a[i + 1][j] == a[i][j]) {
          ans.push_back(data(a[i][j], i + 1, j));
          swap(a[i + 1][j], a[i][j]);
          a[i][j] = 0;
        } else {
          if (j < n) {
            ans.push_back(data(a[i][j], i, j + 1));
            swap(a[i][j], a[i][j + 1]);
          } else {
            ans.push_back(data(a[i][j], i - 1, j));
            swap(a[i][j], a[i - 1][j]);
          }
        }
      }
      i = 2;
      for (int j = 1; j <= head.second - 2; j++) {
        if (!a[i][j]) continue;
        if (a[i - 1][j] == a[i][j]) {
          ans.push_back(data(a[i][j], i - 1, j));
          swap(a[i - 1][j], a[i][j]);
          a[i][j] = 0;
        } else {
          if (j > 1) {
            ans.push_back(data(a[i][j], i, j - 1));
            swap(a[i][j], a[i][j - 1]);
          } else {
            ans.push_back(data(a[i][j], i + 1, j));
            swap(a[i][j], a[i + 1][j]);
            used[i + 1][j] = true;
          }
        }
      }
    } else {
      int i = 3;
      for (int j = head.second; j >= 1; j--) {
        if (used[i][j]) continue;
        if (!a[i][j]) continue;
        if (a[i + 1][j] == a[i][j]) {
          ans.push_back(data(a[i][j], i + 1, j));
          swap(a[i + 1][j], a[i][j]);
          a[i][j] = 0;
        } else {
          if (j < n) {
            ans.push_back(data(a[i][j], i, j + 1));
            swap(a[i][j], a[i][j + 1]);
          } else {
            ans.push_back(data(a[i][j], i - 1, j));
            swap(a[i][j], a[i - 1][j]);
            used[i - 1][j] = true;
          }
        }
      }
      i = 2;
      for (int j = 1; j <= n; j++) {
        if (!a[i][j]) continue;
        if (used[i][j]) continue;
        if (a[i - 1][j] == a[i][j]) {
          ans.push_back(data(a[i][j], i - 1, j));
          swap(a[i - 1][j], a[i][j]);
          a[i][j] = 0;
        } else {
          if (j > 1) {
            ans.push_back(data(a[i][j], i, j - 1));
            swap(a[i][j], a[i][j - 1]);
          } else {
            ans.push_back(data(a[i][j], i + 1, j));
            swap(a[i][j], a[i + 1][j]);
          }
        }
      }
      i = 3;
      for (int j = n; j >= head.second + 2; j--) {
        if (used[i][j]) continue;
        if (!a[i][j]) continue;
        if (a[i + 1][j] == a[i][j]) {
          ans.push_back(data(a[i][j], i + 1, j));
          swap(a[i + 1][j], a[i][j]);
          a[i][j] = 0;
        } else {
          if (j < n) {
            ans.push_back(data(a[i][j], i, j + 1));
            swap(a[i][j], a[i][j + 1]);
          } else {
            ans.push_back(data(a[i][j], i - 1, j));
            swap(a[i][j], a[i - 1][j]);
            used[i - 1][j] = true;
          }
        }
      }
    }
    for (int i = 2; i <= 3; i++) {
      for (int j = 1; j <= n; j++) {
        if (a[i][j]) {
          canDo = true;
          break;
        }
      }
      if (canDo) break;
    }
  }
  printf("%d\n", (int)ans.size());
  for (auto i : ans) printf("%d %d %d\n", i.car, i.row, i.col);
  return 0;
}
