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