#include <bits/stdc++.h>
using namespace std;
int n;
int a[5], b[5], c[5], d[5];
int num, pr_1, pr_2;
int ans = -1;
int main() {
  cin >> n;
  for (int i = 1; i <= 4; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int i = 1; i <= 4; i++) {
    if ((min(a[i], b[i]) + min(c[i], d[i])) <= n) {
      cout << i << " " << min(a[i], b[i]) << " " << n - min(a[i], b[i]) << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
