#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  int q, w, e, r;
  for (int i = 1; i <= 4; i++) {
    cin >> q >> w >> e >> r;
    int a, b;
    a = min(q, w);
    b = min(e, r);
    if (a + b <= n) {
      cout << i << " " << a << " " << n - a;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
