#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, minC1[5], minJ1[5], minC2[5], minJ2[5];
  cin >> n;
  for (int i = 1; i < 5; i++) {
    cin >> minC1[i] >> minJ1[i] >> minC2[i] >> minJ2[i];
  }
  for (int i = 1; i < 5; i++) {
    if (n - minC1[i] - minC2[i] >= 0) {
      cout << i << " " << minC1[i] << " " << n - minC1[i];
      return 0;
    }
    if (n - minC1[i] - minJ2[i] >= 0) {
      cout << i << " " << minC1[i] << " " << n - minC1[i];
      return 0;
    }
    if (n - minJ1[i] - minC2[i] >= 0) {
      cout << i << " " << minJ1[i] << " " << n - minJ1[i];
      return 0;
    }
    if (n - minJ1[i] - minJ2[i] >= 0) {
      cout << i << " " << minJ1[i] << " " << n - minJ1[i];
      return 0;
    }
  }
  cout << -1;
}
