#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int money;
  cin >> money;
  for (int i = 0; i < 4; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (min(a, b) + min(c, d) <= money) {
      cout << i + 1 << " " << min(a, b) << " " << money - min(a, b) << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
