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