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