#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, flag, a1, a2, b2, b1, c, d, x;
  cin >> x;
  for (i = 0; i < 4; i++) {
    cin >> a1 >> b1 >> a2 >> b2;
    flag = 0;
    n = x;
    if (a1 <= b1) {
      n = n - a1;
      c = a1;
    } else {
      n = n - b1;
      c = b1;
    }
    if (a2 <= b2) {
      n = n - a2;
      d = a2;
    } else {
      n = n - b2;
      d = b2;
    }
    if (n < 0) {
      flag = 1;
    } else {
      cout << i + 1 << ' ' << c << ' ' << x - c << endl;
      break;
    }
  }
  if (flag == 1) {
    cout << "-1" << endl;
  }
  return 0;
}
