#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i = 0, solu = 0, menor, precos[4], guarda;
  int c1[4], c2[4], s1[4], s2[4];
  cin >> n;
  while (i != 4) {
    cin >> c1[i] >> s1[i] >> c2[i] >> s2[i];
    i++;
  }
  menor = 500000;
  for (i = 0; i < 4; i++) {
    precos[i] = min(c1[i], s1[i]) + min(c2[i], s2[i]);
    if (precos[i] < menor) {
      menor = precos[i];
      guarda = i;
    }
  }
  if (menor > n) {
    cout << "-1" << endl;
  } else {
    cout << guarda + 1 << " " << min(c1[guarda], s1[guarda]) << " "
         << n - min(c1[guarda], s1[guarda]) << endl;
  }
  return 0;
}
