#include <bits/stdc++.h>
using namespace std;
int N, A, B, C, D;
int main() {
  scanf("%d", &N);
  int i;
  for (i = 1; i <= 4; i++) {
    cin >> A >> B >> C >> D;
    if (min(A, B) + min(C, D) <= N) {
      printf("%d %d %d", i, min(A, B), N - min(A, B));
      break;
    }
  }
  if (i == 5) printf("-1\n");
  return 0;
}
