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