#include <bits/stdc++.h>
using namespace std;
int a[1009], b[1009], c[1009], d[1009], gd[1009];
int main() {
  long long int n, i, gurd1 = 0, gurd2 = 0, g1 = 0, g2 = 0, gx1 = 0, gx2 = 0,
                      ok = 0;
  cin >> n;
  for (i = 0; i < 4; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (i = 0; i < 4; i++) {
    g1 = min(a[i], b[i]);
    g2 = min(c[i], d[i]);
    gx1 = max(a[i], b[i]);
    gx2 = max(c[i], d[i]);
    if ((g1 + g2 > n)) {
      ok = 0;
    } else {
      if (g1 + g2 == n) {
        ok = 1;
        break;
      } else if (g1 + g2 < n) {
        if (gx1 + g2 == n) {
          g1 = gx1;
          ok = 1;
          break;
        } else if (g1 + gx2 == n) {
          g2 = gx2;
          ok = 1;
          break;
        } else if (gx1 + gx2 == n) {
          g1 = gx1;
          g2 = gx2;
          ok = 1;
          break;
        } else if (gx1 + gx2 < n) {
          if (gx1 + (n - gx1) == n) {
            g1 = gx1;
            g2 = n - gx1;
            ok = 1;
            break;
          } else if ((n - gx2) + gx2 == n) {
            g1 = n - gx2;
            g2 = gx2;
            ok = 1;
            break;
          } else {
            g1 = gx1;
            g2 = gx2;
            ok = 1;
            break;
          }
        } else {
          g2 = n - g1;
          ok = 1;
          break;
        }
      }
    }
  }
  if (ok == 1)
    cout << i + 1 << " " << g1 << " " << g2 << endl;
  else
    cout << -1 << endl;
}
