#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, minx;
  int x[4][4];
  int v[4][4];
  cin >> n;
  for (int j = 0; j < 4; j++) {
    cin >> x[j][0] >> x[j][1] >> x[j][2] >> x[j][3];
  }
  for (int i = 0; i < 4; i++) {
    v[i][0] = i + 1;
    v[i][1] = min(x[i][0], x[i][1]);
    v[i][2] = min(x[i][2], x[i][3]);
    v[i][3] = (v[i][1] + v[i][2]);
  }
  minx = min(min(v[0][3], v[1][3]), min(v[2][3], v[3][3]));
  for (int i = 0; i < 4; i++) {
    if (n < minx) {
      cout << "-1" << endl;
      break;
    }
    if (minx == v[i][3]) {
      cout << v[i][0] << ' ' << v[i][1] << ' ' << n - v[i][1] << endl;
      break;
    }
  }
  return 0;
}
