#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool elem(set<T> st, T val) {
  return (st.find(val) != st.end());
}
template <typename T>
void printv(vector<T> vt) {
  for (int i = 0; i < (int)vt.size() - 1; ++i) cout << vt[i] << " ";
  cout << vt[vt.size() - 1] << endl;
}
int d[4][4];
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < (int)4; ++i) {
    for (int j = 0; j < (int)4; ++j) cin >> d[i][j];
  }
  int mn = 1000000;
  int mnp = -1;
  for (int i = 0; i < (int)4; ++i) {
    int r = ((d[i][0]) > (d[i][1])) ? (d[i][1]) : (d[i][0]);
    int l = ((d[i][2]) > (d[i][3])) ? (d[i][3]) : (d[i][2]);
    if (r + l <= n) {
      mn = ((d[i][0]) > (d[i][1])) ? (d[i][1]) : (d[i][0]);
      mnp = i;
    }
  }
  if (mnp == -1)
    cout << -1 << endl;
  else
    cout << mnp + 1 << " " << mn << " " << n - mn << endl;
  return 0;
}
