#include <bits/stdc++.h>
using namespace std;
int d1[5], c1[5], d2[5], c2[5];
int min2[5], min1[5];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 4; i++) {
    cin >> c1[i] >> d1[i] >> c2[i] >> d2[i];
    min1[i] = min(c1[i], d1[i]);
    min2[i] = min(c2[i], d2[i]);
  }
  int tmp = 1e9;
  int it;
  for (int i = 1; i <= 4; i++)
    if (min1[i] + min2[i] < tmp) {
      tmp = min1[i] + min2[i];
      it = i;
    }
  if (tmp > n)
    cout << -1;
  else
    cout << it << " " << min1[it] << " " << n - min1[it];
  return 0;
}
