#include <bits/stdc++.h>
int a, b, c, d, n;
int main() {
  while (~scanf("%d", &n)) {
    int x = -1, y = -1, p = -1;
    for (int i = 0; i < 4; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      if (a + c <= n) x = a, y = n - a, p = i + 1;
      if (b + d <= n) x = b, y = n - b, p = i + 1;
      if (a + d <= n) x = a, y = n - a, p = i + 1;
      if (b + c <= n) x = b, y = n - b, p = i + 1;
    }
    if (p == -1)
      printf("%d\n", p);
    else
      printf("%d %d %d\n", p, x, y);
  }
  return 0;
}
