#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[10], b[10], c[10], d[10], ckl[10], ju[10];
  for (int i = 0; i < 4; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (int i = 0; i < 4; i++) {
    if (min(a[i], b[i]) + min(c[i], d[i]) <= n) {
      int x = min(a[i], b[i]), y = min(c[i], d[i]);
      cout << i + 1 << " " << x << " " << n - x << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
