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