#include <bits/stdc++.h>
using namespace std;
int N, a, b, c, d, mn, mx, ind, changeA, changeB;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  mn = 2 * 1000 * 1000;
  for (int i = 1; i <= 4; i++) {
    cin >> a >> b >> c >> d;
    int mn1 = min(a, b), mn2 = min(c, d);
    int edor = mn1 + mn2;
    if (edor < mn) {
      mn = edor;
      ind = i;
      changeA = min(a, b);
      changeB = min(c, d);
    }
  }
  if (changeA + changeB > N) return cout << -1 << endl, 0;
  cout << ind << " " << changeA << " " << N - changeA << endl;
  return 0;
}
