#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= 4; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (min(a, b) + min(c, d) <= n) {
      cout << i << " " << min(a, b) << " " << n - min(a, b) << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
