#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 4; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for (int p1 = a; p1 < n; p1++) {
      if (n - p1 >= c || n - p1 >= d) {
        cout << i + 1 << " " << p1 << " " << n - p1 << endl;
        return 0;
      }
    }
    for (int p1 = b; p1 < n; p1++) {
      if (n - p1 >= c || n - p1 >= d) {
        cout << i + 1 << " " << p1 << " " << n - p1 << endl;
        return 0;
      }
    }
  }
  cout << "-1\n";
  return 0;
}
