#include <bits/stdc++.h>
int min(int a, int b) { return a > b ? b : a; }
int max(int a, int b) { return a < b ? b : a; }
int main() {
  int n, a, b, c, d, i, pos;
  int sum, next;
  while (~scanf("%d", &n)) {
    int ans = 0;
    for (i = 1; i <= 4; i++) {
      scanf("%d%d%d%d", &a, &b, &c, &d);
      a = min(a, b);
      b = max(a, b);
      c = min(c, d);
      d = max(c, d);
      if (a + c <= n) {
        ans = 1;
        pos = i;
        next = a;
      }
    }
    if (ans)
      printf("%d %d %d\n", pos, next, n - next);
    else
      printf("-1\n");
  }
  return 0;
}
