#include <bits/stdc++.h>
int main() {
  int a, b, c, d, n, i, j, q, w, e, r;
  scanf("%d", &n);
  for (i = 1; i <= 4; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a < b) b = a;
    if (c < d) d = c;
    if (b + d <= n) {
      for (j = i; j < 4; j++) scanf("%d %d %d %d", &q, &w, &e, &r);
      printf("%d %d %d", i, b, n - b);
      break;
    }
    if (i == 4) printf("-1");
  }
}
