#include <bits/stdc++.h>
using namespace std;
struct Move {
  int i, r, c;
};
int main() {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int> > a(4);
  for (int i = 0; i < 4; ++i) a[i].resize(n);
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  vector<Move> m;
  Move t;
  for (int i = 1; i < 3; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == 1 && a[i][j] && a[i][j] == a[0][j]) {
        t.i = a[0][j];
        t.r = 1;
        t.c = j + 1;
        m.push_back(t);
        a[i][j] = 0;
      } else if (i == 2 && a[i][j] && a[i][j] == a[3][j]) {
        t.i = a[3][j];
        t.r = 4;
        t.c = j + 1;
        m.push_back(t);
        a[i][j] = 0;
      }
    }
  }
  int f = 0;
  for (int i = 1; i < 3; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a[i][j] == 0) f++;
    }
  }
  if (f == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (f < 2 * n) {
    for (int i = 1; i < 3; ++i) {
      if (i == 1) {
        for (int j = 0; j < n; ++j) {
          if (a[i][j] && a[i][j] == a[0][j]) {
            t.i = a[0][j];
            t.r = 1;
            t.c = j + 1;
            m.push_back(t);
            a[i][j] = 0;
          }
          if (j < n - 1 && a[i][j] && a[i][j + 1] == 0) {
            a[i][j + 1] = a[i][j];
            a[i][j] = 0;
            t.i = a[i][j + 1];
            t.r = i + 1;
            t.c = j + 2;
            m.push_back(t);
          } else if (j == n - 1 && a[i][j] && a[i + 1][j] == 0) {
            a[i + 1][j] = a[i][j];
            a[i][j] = 0;
            t.i = a[i + 1][j];
            t.r = i + 2;
            t.c = j + 1;
            m.push_back(t);
          }
        }
      } else if (i == 2) {
        for (int j = n - 1; j >= 0; --j) {
          if (a[i][j] && a[i][j] == a[3][j]) {
            t.i = a[3][j];
            t.r = 4;
            t.c = j + 1;
            m.push_back(t);
            a[i][j] = 0;
          }
          if (j > 0 && a[i][j] && a[i][j - 1] == 0) {
            a[i][j - 1] = a[i][j];
            a[i][j] = 0;
            t.i = a[i][j - 1];
            t.r = i + 1;
            t.c = j;
            m.push_back(t);
          } else if (j == 0 && a[i][j] && a[i - 1][j] == 0) {
            a[i - 1][j] = a[i][j];
            a[i][j] = 0;
            t.i = a[i - 1][j];
            t.r = i;
            t.c = j + 1;
            m.push_back(t);
          }
        }
      }
    }
    for (int i = 1; i < 3; ++i) {
      for (int j = 0; j < n; ++j) {
        if (i == 1 && a[i][j] && a[i][j] == a[0][j]) {
          t.i = a[0][j];
          t.r = 1;
          t.c = j + 1;
          m.push_back(t);
          a[i][j] = 0;
        } else if (i == 2 && a[i][j] && a[i][j] == a[3][j]) {
          t.i = a[3][j];
          t.r = 4;
          t.c = j + 1;
          m.push_back(t);
          a[i][j] = 0;
        }
      }
    }
    f = 0;
    for (int i = 1; i < 3; ++i) {
      for (int j = 0; j < n; ++j) {
        if (a[i][j] == 0) f++;
      }
    }
  }
  cout << m.size() << endl;
  for (int i = 0; i < m.size(); ++i)
    cout << m[i].i << " " << m[i].r << " " << m[i].c << endl;
  return 0;
}
