#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b[5], c[5], d[5], e[5], f = 0, g = 0, h = 0, k = 0, l = 0,
                                           m = 0, n = 0, i, j;
  cin >> a;
  for (i = 1; i <= 4; i++) {
    cin >> b[i] >> c[i] >> d[i] >> e[i];
  }
  for (i = 1; i <= 4; i++) {
    if (k == 0) {
      if (b[i] >= c[i]) {
        l = c[i];
      } else if (c[i] > b[i]) {
        l = b[i];
      }
      if (d[i] >= e[i]) {
        m = e[i];
      } else if (e[i] > d[i]) {
        m = d[i];
      }
      if (m + l <= a) {
        f = i;
        g = l;
        h = m;
        k++;
      }
    } else if (k == 1) {
      if (b[i] >= c[i]) {
        l = c[i];
      } else if (c[i] > b[i]) {
        l = b[i];
      }
      if (d[i] >= e[i]) {
        m = e[i];
      } else if (e[i] > d[i]) {
        m = d[i];
      }
      if (m + l <= a && m + l < g + h) {
        f = i;
        g = l;
        h = m;
      }
    }
  }
  if (g + h < a && g != 0 && h != 0 && f != 0) {
    cout << f << " " << g << " " << a - g << endl;
  } else if (g + h == a) {
    cout << f << " " << g << " " << h << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
