#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, a[5], b[5], c[5], d[5], e[5], f[5], g[5];
  cin >> n;
  for (int i = 0; i <= 3; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (int i = 0; i <= 3; i++) {
    if (a[i] <= b[i])
      e[i] = a[i];
    else
      e[i] = b[i];
    if (c[i] <= d[i])
      f[i] = c[i];
    else
      f[i] = d[i];
    g[i] = e[i] + f[i];
  }
  int minn = 100005;
  for (int i = 0; i <= 3; i++) {
    if (g[i] < minn) {
      minn = g[i];
      t = i + 1;
    }
  }
  if (n >= minn)
    cout << t << ' ' << e[t - 1] << ' ' << n - e[t - 1] << endl;
  else
    cout << -1 << endl;
  return 0;
}
