#include <bits/stdc++.h>
using namespace std;
int n, num[4][4];
int main() {
  cin >> n;
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 4; ++j) cin >> num[i][j];
  int Min = 1e9, Minn = 0, Minf = 1e9, Mins = 1e9;
  for (int i = 0; i < 4; ++i)
    if (Min > min(num[i][0], num[i][1]) + min(num[i][2], num[i][3])) {
      Minf = min(num[i][0], num[i][1]);
      Mins = min(num[i][2], num[i][3]);
      Min = Minf + Mins;
      Minn = i + 1;
    }
  if (Min > n) {
    cout << -1 << endl;
    return 0;
  }
  cout << Minn << ' ' << Minf << ' ' << n - Minf << endl;
  return 0;
}
