#include <bits/stdc++.h>
using namespace std;
int main() {
  int num = 4;
  int kane;
  int input[4][4];
  cin >> kane;
  int min = 200001;
  int kai = -1;
  int mina, minb;
  int min1, min2;
  for (int i = 0; i < num; i++) {
    cin >> input[i][0] >> input[i][1] >> input[i][2] >> input[i][3];
    mina = (input[i][0] < input[i][1]) ? input[i][0] : input[i][1];
    minb = (input[i][2] < input[i][3]) ? input[i][2] : input[i][3];
    if (min >= mina + minb) {
      min = mina + minb;
      min1 = mina;
      min2 = minb;
      if (min <= kane) kai = i + 1;
    }
  }
  if (kai != -1) {
    cout << kai << " " << min1 << " " << kane - min1 << endl;
  } else
    cout << -1;
}
