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