#include <bits/stdc++.h>
using namespace std;
int N[5], M[5];
int main() {
  int sum, a, b, c, d;
  scanf("%d", &sum);
  for (int ix = 1; ix <= 4; ix++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    N[ix] = min(a, b);
    M[ix] = min(c, d);
  }
  for (int ix = 1; ix <= 4; ix++)
    if (N[ix] + M[ix] <= sum) {
      cout << ix << " " << N[ix] << " " << sum - N[ix] << endl;
      return 0;
    }
  cout << -1 << endl;
}
