#include <bits/stdc++.h>
using namespace std;
int num[10][10];
int main() {
  int n;
  int a, b, ans;
  int c, d;
  int cur;
  while (scanf("%d", &n) > 0) {
    ans = 1000000;
    cur = 0;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) scanf("%d", &num[i][j]);
    for (int i = 0; i < 4; i++) {
      int a = min(num[i][0], num[i][1]);
      int b = min(num[i][2], num[i][3]);
      if (a + b < ans) {
        ans = a + b;
        c = a;
        d = b;
        cur = i;
      }
    }
    if (ans <= n) {
      if (c > d)
        d = n - c;
      else
        c = n - d;
      printf("%d %d %d\n", cur + 1, c, d);
    } else
      printf("-1\n");
  }
}
