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