#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<vector<int> > r(4, vector<int>(n));
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> r[i][j];
    }
  }
  vector<pair<int, pair<int, int> > > v;
  int yy, xx;
  if (k == 2 * n) {
    bool flag = false;
    for (int i = 0; i < n; i++) {
      if (r[1][i] == r[0][i]) {
        flag = true;
        yy = i;
        xx = 1;
        k--;
        v.push_back({r[1][i], {1, i + 1}});
        break;
      }
    }
    if (!flag)
      for (int i = 0; i < n; i++) {
        if (r[2][i] == r[3][i]) {
          flag = true;
          yy = i;
          xx = 2;
          k--;
          v.push_back({r[2][i], {4, i + 1}});
          break;
        }
      }
    if (!flag) {
      cout << -1;
      return 0;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (r[1][i] == 0) {
        yy = i;
        xx = 1;
      }
      if (r[2][i] == 0) {
        yy = i;
        xx = 2;
      }
    }
  }
  if (yy == n - 1 && xx == 1) {
    xx = 2;
  } else if (yy == 0 && xx == 2) {
    xx = 1;
  } else if (xx == 1) {
    yy++;
  } else if (xx == 2)
    yy--;
  while (k != 0) {
    if (r[xx][yy] != 0) {
      if (xx == 1 && r[xx][yy] == r[0][yy]) {
        v.push_back({r[xx][yy], {1, yy + 1}});
        r[xx][yy] = 0;
        k--;
      } else {
        if (xx == 2 && r[xx][yy] == r[3][yy]) {
          v.push_back({r[xx][yy], {4, yy + 1}});
          r[xx][yy] = 0;
          k--;
        } else {
          if (yy == n - 1 && xx == 2) {
            v.push_back({r[xx][yy], {2, yy + 1}});
            r[1][yy] = r[xx][yy];
            r[xx][yy] = 0;
          } else if (yy == 0 && xx == 1) {
            v.push_back({r[xx][yy], {3, yy + 1}});
            r[2][yy] = r[xx][yy];
            r[xx][yy] = 0;
          } else if (xx == 1) {
            v.push_back({r[xx][yy], {xx + 1, yy - 1 + 1}});
            r[xx][yy - 1] = r[xx][yy];
            r[xx][yy] = 0;
          } else if (xx == 2) {
            v.push_back({r[xx][yy], {xx + 1, yy + 1 + 1}});
            r[xx][yy + 1] = r[xx][yy];
            r[xx][yy] = 0;
          }
        }
      }
    }
    if (yy == n - 1 && xx == 1) {
      xx = 2;
    } else if (yy == 0 && xx == 2) {
      xx = 1;
    } else if (xx == 1) {
      yy++;
    } else if (xx == 2)
      yy--;
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second.first << " " << v[i].second.second
         << endl;
  }
  return 0;
}
