#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k = 4, count = 0, flag = 0;
  cin >> n;
  int a, b, c, d;
  while (k--) {
    cin >> a >> b >> c >> d;
    count++;
    if (flag == 0) {
      if (min(a, b) + min(c, d) == n) {
        flag = 1;
        cout << count << " " << min(a, b) << " " << min(c, d) << endl;
      } else if (min(a, b) + min(c, d) < n) {
        cout << count << " " << min(a, b) << " " << n - min(a, b) << endl;
        flag = 1;
      }
    }
  }
  if (flag == 0) cout << -1 << endl;
  return 0;
}
