#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int minsum = 1e9, fst, sec, minidx;
  for (int i = 0; i < 4; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a = min(a, b);
    b = min(c, d);
    if (a + b < minsum) {
      fst = a;
      sec = b;
      minsum = a + b;
      minidx = i;
    }
  }
  if (minsum > n) {
    cout << -1;
  } else {
    cout << minidx + 1 << ' ' << fst << ' ' << n - fst;
  }
  return 0;
}
