#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
  long n;
  cin >> n;
  bool dd = false;
  for (long i = 0; i < (4); ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (dd) continue;
    if (min(a, b) + min(c, d) <= n) {
      cout << i + 1 << " " << min(a, b) << " " << n - min(a, b) << endl;
      dd = true;
    }
  }
  if (dd == false) cout << "-1" << endl;
  return 0;
}
