#include <bits/stdc++.h>
using namespace std;
int N;
int a, b, c, d;
int ans = -2, x;
int main() {
  int i;
  scanf("%d", &N);
  for (i = 1; i <= 4; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int xx = min(a, b) + min(c, d);
    if (N >= xx) {
      ans = i;
      x = min(a, b);
    }
  }
  if (ans != -2)
    printf("%d %d %d\n", ans, x, N - x);
  else
    printf("-1\n");
}
