#include <bits/stdc++.h>
int IMIN(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int main() {
  int a, b[4][4], i, j, c, d;
  scanf("%d", &a);
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) scanf("%d", &b[i][j]);
  }
  for (i = 0; i < 4; i++) {
    c = IMIN(b[i][0], b[i][1]);
    d = IMIN(b[i][2], b[i][3]);
    if ((c + d) <= a) break;
  }
  if (i == 4)
    printf("-1\n");
  else {
    c = IMIN(b[i][0], b[i][1]);
    printf("%d %d %d\n", i + 1, c, a - c);
  }
  return 0;
}
