#include <bits/stdc++.h>
using namespace std;
long long n, a, b, c, d, i, ans, ans1, ans2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i <= 4; i++) {
    cin >> a >> b >> c >> d;
    if (min(a, b) + min(c, d) <= n) {
      ans = i;
      ans1 = min(a, b);
      ans2 = n - ans1;
    }
  }
  if (ans != 0)
    cout << ans << " " << ans1 << " " << ans2 << '\n';
  else
    cout << "-1" << '\n';
  return 0;
}
