#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a, b, c, d;
int main() {
  while (~scanf("%d", &n)) {
    int ok = -1;
    int ans1, ans2;
    for (int i = 0; i < 4; ++i) {
      scanf("%d%d%d%d", &a, &b, &c, &d);
      if (ok == -1) {
        if (a + c <= n || a + d <= n || b + c <= n || b + d <= n) {
          ok = i + 1;
          if (a + c <= n || a + d <= n) {
            ans1 = a;
            ans2 = n - a;
          } else {
            ans1 = b;
            ans2 = n - b;
          }
        }
      }
    }
    if (ok != -1) {
      printf("%d %d %d\n", ok, ans1, ans2);
    } else
      printf("-1\n");
  }
  return 0;
}
