#include <bits/stdc++.h>
using namespace std;
int min(int x, int y) { return (x > y) ? y : x; }
int main() {
  int n;
  scanf("%d", &n);
  int yo[5][5];
  for (int i = 1; i <= 4; i++) {
    scanf("%d", &yo[i][1]);
    scanf("%d", &yo[i][2]);
    scanf("%d", &yo[i][3]);
    scanf("%d", &yo[i][4]);
    yo[i][0] = min(yo[i][1], yo[i][2]) + min(yo[i][3], yo[i][4]);
  }
  int mini = 10000000;
  int mi = -1;
  for (int i = 1; i <= 4; i++) {
    if (yo[i][0] < mini) {
      mini = yo[i][0];
      mi = i;
    }
  }
  if (mini > n)
    printf("-1\n");
  else {
    printf("%d %d %d\n", mi, min(yo[mi][1], yo[mi][2]),
           n - min(yo[mi][1], yo[mi][2]));
  }
}
