#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, c, a, d, e, f, q, w, z, ans = 1, b;
  scanf("%d", &n);
  for (i = 0; i < 4; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    e = a < b ? a : b;
    f = c < d ? c : d;
    if (e + f <= n) {
      q = i + 1;
      w = e;
      z = n - e;
      ans = 0;
    }
  }
  if (ans != 0)
    printf("-1\n");
  else
    printf("%d %d %d\n", q, w, z);
  return 0;
}
