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