#include <bits/stdc++.h>
using namespace std;
int n;
int a[8], b[5], c[6], d[6];
int main() {
  cin >> n;
  for (int i = 0; i < 4; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int i = 0; i < 4; i++) {
    if (a[i] + c[i] <= n) {
      cout << i + 1 << " " << a[i] << " " << n - a[i] << endl;
      return 0;
    }
    if (a[i] + d[i] <= n) {
      cout << i + 1 << " " << a[i] << " " << n - a[i] << endl;
      return 0;
    }
    if (b[i] + c[i] <= n || b[i] + d[i] <= n) {
      cout << i + 1 << " " << b[i] << " " << n - b[i] << endl;
      return 0;
    }
  }
  puts("-1");
}
