#include <bits/stdc++.h>
using namespace std;
int p[4][4];
int main() {
  int n, j, i;
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < 4; i++)
      for (j = 0; j < 4; j++) scanf("%d", &p[i][j]);
    int minn = 999999999;
    int f = 0;
    for (i = 0; i < 4; i++) {
      int cnt = min(p[i][0], p[i][1]) + min(p[i][2], p[i][3]);
      if (minn > cnt) {
        minn = cnt;
        f = i;
      }
    }
    if (n < minn)
      printf("-1\n");
    else
      printf("%d %d %d\n", f + 1, min(p[f][0], p[f][1]),
             n - min(p[f][0], p[f][1]));
  }
  return 0;
}
