#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int a[4][4];
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; j++) cin >> a[i][j];
  }
  int t = -1;
  for (int i = 0; i < 4; i++) {
    if (min(a[i][0], a[i][1]) + min(a[i][2], a[i][3]) <= n) {
      t = i;
      break;
    }
  }
  if (t != -1) {
    cout << t + 1 << " ";
    cout << min(a[t][0], a[t][1]) << " ";
    cout << n - min(a[t][0], a[t][1]) << endl;
  } else
    cout << -1 << endl;
  return 0;
}
