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