#include <bits/stdc++.h>
using namespace std;
int a[4];
struct Node {
  int v, id, x1, y1;
};
Node p[4];
bool cmp(const Node &a, const Node &b) { return a.v < b.v; }
int main() {
  int n, a, b, c, d;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    cin >> a >> b >> c >> d;
    p[i].v = min(a, b) + min(c, d);
    p[i].id = i + 1;
    p[i].x1 = min(a, b);
    p[i].y1 = min(c, d);
  }
  sort(p, p + 4, cmp);
  if (p[0].v <= n)
    cout << p[0].id << " " << p[0].x1 << " " << n - p[0].x1 << endl;
  else
    cout << -1 << endl;
  return 0;
}
