#include <bits/stdc++.h>
using namespace std;
struct tp {
  int i, r, c;
};
int n, k;
int a[5][101];
vector<tp> pol;
void moveDownRight(int i1, int j1) {
  for (int i = i1; i >= j1; i--) {
    if (a[3][i] != 0) {
      pol.push_back({a[3][i], 3, i + 1});
      a[3][i + 1] = a[3][i];
      a[3][i] = 0;
    }
  }
}
void moveUpLeft(int i1, int j1) {
  for (int i = i1; i <= j1; i++) {
    if (a[2][i] != 0) {
      pol.push_back({a[2][i], 2, i - 1});
      a[2][i - 1] = a[2][i];
      a[2][i] = 0;
    }
  }
}
void moveVn() {
  if (a[2][1] != 0 && a[3][1] == 0) {
    pol.push_back({a[2][1], 3, 1});
    a[3][1] = a[2][1];
    a[2][1] = 0;
  }
}
void moveVv() {
  if (a[3][n] != 0) {
    pol.push_back({a[3][n], 2, n});
    a[2][n] = a[3][n];
    a[3][n] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  if (n == 1) {
    if (k == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (k == 1) {
      if (a[1][1] != 0) {
        if (a[2][1] != 0) {
          cout << 1 << endl;
          cout << 1 << " " << 1 << " " << 1 << endl;
          return 0;
        } else {
          cout << 2 << endl;
          cout << 1 << " " << 2 << " " << 1 << endl;
          cout << 1 << " " << 1 << " " << 1 << endl;
          return 0;
        }
      } else {
        if (a[3][1] != 0) {
          cout << 1 << endl;
          cout << 1 << " " << 4 << " " << 1 << endl;
          return 0;
        } else {
          cout << 2 << endl;
          cout << 1 << " " << 3 << " " << 1 << endl;
          cout << 1 << " " << 4 << " " << 1 << endl;
          return 0;
        }
      }
    } else {
      if (a[1][1] == a[2][1]) {
        cout << 2 << endl;
        cout << a[1][1] << " " << 1 << " " << 1 << endl;
        cout << a[4][1] << " " << 4 << " " << 1 << endl;
        return 0;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int cr = k;
  while (cr > 0) {
    for (int i = 1; i <= n; i++) {
      if (a[1][i] != 0 && a[1][i] == a[2][i]) {
        cr--;
        pol.push_back({a[2][i], 1, i});
        a[1][i] = 0;
        a[2][i] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (a[3][i] != 0 && a[3][i] == a[4][i]) {
        cr--;
        pol.push_back({a[3][i], 4, i});
        a[3][i] = 0;
        a[4][i] = 0;
      }
    }
    if (a[2][1] != 0 && a[3][1] == 0) {
      moveVn();
      moveUpLeft(2, n);
      moveVv();
      moveDownRight(n - 1, 2);
    } else if (a[3][n] != 0 && a[2][n] == 0) {
      moveVv();
      moveDownRight(n - 1, 1);
      moveVn();
      moveUpLeft(2, n - 1);
    } else {
      bool good = false;
      int k = 0;
      for (int i = 2; i <= n; i++) {
        if (a[2][i] != 0 && a[2][i - 1] == 0) {
          good = true;
          k = i;
          break;
        }
      }
      if (good) {
        for (int i = k; i <= n; i++) {
          if (a[2][i] != 0) {
            pol.push_back({a[2][i], 2, i - 1});
            a[2][i - 1] = a[2][i];
            a[2][i] = 0;
          }
        }
        moveVv();
        moveDownRight(n - 1, 1);
        if (k != 2) {
          moveVn();
        }
        for (int i = 2; i < k - 1; i++) {
          if (a[2][i] != 0) {
            pol.push_back({a[2][i], 2, i - 1});
            a[2][i - 1] = a[2][i];
            a[2][i] = 0;
          }
        }
      } else {
        good = false;
        k = 0;
        for (int i = 1; i < n; i++) {
          if (a[3][i] != 0 && a[3][i + 1] == 0) {
            good = true;
            k = i;
            break;
          }
        }
        if (good) {
          for (int i = k; i >= 1; i--) {
            if (a[3][i] != 0) {
              pol.push_back({a[3][i], 3, i + 1});
              a[3][i + 1] = a[3][i];
              a[3][i] = 0;
            }
          }
          moveVn();
          moveUpLeft(2, n);
          if (k != n - 1) {
            moveVv();
          }
          for (int i = n - 1; i > k + 1; i--) {
            if (a[3][i] != 0) {
              pol.push_back({a[3][i], 3, i + 1});
              a[3][i + 1] = a[3][i];
              a[3][i] = 0;
            }
          }
        } else {
          if (cr > 0) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << pol.size() << endl;
  for (auto x : pol) {
    cout << x.i << " " << x.r << " " << x.c << endl;
  }
  return 0;
}
