#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  int best = -1;
  int idx, op1, op2;
  for (int i = 0; i < 4; i++) {
    int v1, v2, v3, v4;
    cin >> v1 >> v2 >> v3 >> v4;
    int temp = min(v1, v2) + min(v3, v4);
    if (temp > n) continue;
    if (best == -1 || temp < best) {
      best = temp;
      idx = i + 1;
      op1 = min(v1, v2);
      op2 = min(v3, v4);
    }
  }
  if (best == -1)
    cout << best << '\n';
  else {
    int left = n - op1 - op2;
    op1 += left;
    cout << idx << ' ' << op1 << ' ' << op2;
  }
  return 0;
}
