#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c, d, res1, res2, res3;
  bool ok = 0;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    cin >> a >> b >> c >> d;
    a = min(a, b), c = min(c, d);
    if (!ok && a + c <= n) {
      ok = 1;
      res1 = i + 1, res2 = a, res3 = n - a;
    }
  }
  if (ok)
    cout << res1 << " " << res2 << " " << res3 << endl;
  else
    cout << -1 << endl;
  return 0;
}
