#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000")
using namespace std;
const double EPS = 1e-9;
const int INF = (int)(1e9 + 0.5);
const int MAXN = 100001;
int main() {
  int n, ans = -1;
  cin >> n;
  for (int i = 0; i < 4; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c <= n - min(a, b)) {
      cout << i + 1 << " " << min(a, b) << " " << n - min(a, b) << endl;
      exit(0);
    } else {
      if (d <= n - min(a, b)) {
        cout << i + 1 << " " << min(a, b) << " " << n - min(a, b) << endl;
        exit(0);
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}
