#include <bits/stdc++.h>
using namespace std;
int main() {
  int tot;
  int ans = -1;
  int aa[5], bb[5], cc[5], x1, x2, y1, y2;
  scanf("%d", &tot);
  for (int i = 0; i < 4; i++) {
    scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
    aa[i] = min(x1, x2);
    bb[i] = min(y1, y2);
    cc[i] = aa[i] + bb[i];
    if (cc[i] <= tot) ans = i;
  }
  if (ans == -1)
    printf("-1\n");
  else
    printf("%d %d %d", ans + 1, aa[ans], tot - aa[ans]);
}
