#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a, b, c, d, k, i, p, q;
  k = 4;
  int max = -1;
  for (int i = 1; i <= 4; i++) {
    cin >> a >> b >> c >> d;
    if (a + c <= n) {
      max = i;
      p = a;
      q = n - a;
    }
    if (a + d <= n) {
      max = i;
      p = a;
      q = n - a;
    }
    if (b + c <= n) {
      max = i;
      p = b;
      q = n - b;
    }
    if (b + d <= n) {
      max = i;
      p = b;
      q = n - b;
    }
  }
  if (max == -1) {
    puts("-1");
  } else {
    printf("%d %d %d\n", max, p, q);
  }
  return 0;
}
