#include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c, d;
int main() {
  cin >> n;
  int e, f;
  int num = -1, aa, bb;
  for (int i = 1; i < 5; i++) {
    cin >> a >> b >> c >> d;
    a = min(a, b);
    c = min(c, d);
    if (a + c <= n) {
      num = i;
      aa = a;
      bb = n - aa;
    }
  }
  if (num > -1) {
    cout << num << " " << aa << " " << bb << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
