#include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c, d;
int res1, res2;
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < 4; i++) {
    cin >> a >> b >> c >> d;
    res1 = min(a, b);
    res2 = min(c, d);
    if (res1 + res2 <= n) {
      cout << i + 1 << " " << res1 << " " << n - res1;
      return;
    }
  }
  cout << -1;
}
int main() {
  solve();
  return 0;
}
