#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, a, b, c, d, p1, p2, ans1, ans2, idx;
  while (scanf("%d", &n) != EOF) {
    idx = -1;
    for (i = 1; i <= 4; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      p1 = min(a, b);
      p2 = min(c, d);
      if (p1 + p2 <= n) {
        idx = i;
        ans1 = p1;
        ans2 = n - p1;
      }
    }
    if (idx == -1)
      printf("-1\n");
    else
      printf("%d %d %d\n", idx, ans1, ans2);
  }
  return 0;
}
