#include <bits/stdc++.h>
using namespace std;
int n, minJuice, minChoc, a, b, c, d, success = 0;
int main() {
  cin >> n;
  for (int i = 1; i <= 4 && !success; i++) {
    cin >> a >> b >> c >> d;
    minJuice = min(a, b);
    minChoc = min(c, d);
    if (minJuice + minChoc <= n) {
      success = 1;
      cout << i << ' ' << minJuice << ' ' << n - minJuice;
    }
  }
  if (!success) cout << "-1";
}
