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