#include <bits/stdc++.h>
using namespace std;
int n, k;
int arr[4][55];
vector<pair<int, pair<int, int> > > ans;
void print();
void go() {
  int curx = -1;
  int cury = -1;
  for (int i = 1; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[i][j] == 0) {
        curx = j;
        cury = i;
      }
    }
  }
  if (curx == -1) return;
  int steps = 0;
  while (steps < 2 * n) {
    if (arr[cury][curx] != 0) {
      int tox = curx;
      int toy = cury;
      if (cury == 1) {
        if (curx == 0) {
          tox = 0;
          toy = 2;
        } else {
          tox--;
        }
      } else {
        if (curx == n - 1) {
          toy = 1;
        } else {
          tox++;
        }
      }
      arr[toy][tox] = arr[cury][curx];
      pair<int, pair<int, int> > next;
      next.first = arr[cury][curx];
      pair<int, int> l;
      l.first = (tox + 1);
      l.second = (toy + 1);
      next.second = l;
      ans.push_back(next);
      arr[cury][curx] = 0;
      print();
    }
    if (cury == 1) {
      curx++;
      if (curx == n) {
        curx--;
        cury++;
      }
    } else {
      curx--;
      if (curx == -1) {
        curx++;
        cury--;
      }
    }
    steps++;
  }
}
void print() {}
bool push() {
  bool fl = false;
  for (int i = 0; i < n; i++) {
    if (arr[0][i] == arr[1][i] && arr[0][i] != 0) {
      arr[1][i] = 0;
      pair<int, pair<int, int> > next;
      next.first = arr[0][i];
      pair<int, int> l;
      l.first = (i + 1);
      l.second = 1;
      next.second = l;
      ans.push_back(next);
    }
    if (arr[2][i] == arr[3][i] && arr[3][i] != 0) {
      arr[2][i] = 0;
      pair<int, pair<int, int> > next;
      next.first = arr[3][i];
      pair<int, int> l;
      l.first = (i + 1);
      l.second = 4;
      next.second = l;
      ans.push_back(next);
    }
    if (arr[1][i] + arr[2][i] > 0) fl = true;
  }
  return fl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> arr[i][j];
    }
  }
  push();
  if (n * 2 == k) {
    bool f = true;
    for (int i = 0; i < n; i++) {
      f &= (arr[0][i] == arr[1][i]) && (arr[2][i] == arr[3][i]);
      if (arr[1][i] * arr[2][i] == 0) {
        f = true;
        break;
      }
    }
    if (!f) {
      cout << -1;
      return 0;
    }
  }
  while (true) {
    if (!push()) break;
    go();
  }
  cout << ans.size() << endl;
  for (pair<int, pair<int, int> > d : ans) {
    cout << d.first << " " << d.second.second << " " << d.second.first << endl;
  }
  return 0;
}
