#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
template <class T>
inline void smin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void smax(T &a, T b) {
  if (a < b) a = b;
}
int main() {
  int N, i, a, b, c, d, res1, res2, resid;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (min(a, b) + min(c, d) > N)
      continue;
    else {
      res1 = min(a, b);
      res2 = N - res1;
      resid = i;
      break;
    }
  }
  if (i == N)
    puts("-1");
  else
    printf("%d %d %d\n", resid + 1, res1, res2);
  return 0;
}
