#include <bits/stdc++.h>
using namespace std;
int n, i = 0;
int p[4][4], q[4][2], sum[4];
int main() {
  cin >> n;
  for (i = 0; i < 4; i++) {
    cin >> p[i][0] >> p[i][1] >> p[i][2] >> p[i][3];
    p[i][0] >= p[i][1] ? q[i][0] = p[i][1] : q[i][0] = p[i][0];
    p[i][2] >= p[i][3] ? q[i][1] = p[i][3] : q[i][1] = p[i][2];
    sum[i] = q[i][0] + q[i][1];
  }
  for (i = 0; i < 4; i++) {
    if (sum[i] <= n) {
      cout << i + 1 << " " << q[i][0] << " " << n - q[i][0] << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
