#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000 * 100;
int a[MaxN][4];
int n;
bool ok(int pos) {
  int cur1 = min(a[pos][0], a[pos][1]);
  int cur2 = min(a[pos][2], a[pos][3]);
  if (cur1 + cur2 <= n) {
    cur1 = n - cur2;
    printf("%d %d %d", pos + 1, cur1, cur2);
    return true;
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < 4; i++)
    if (ok(i)) return 0;
  printf("-1");
}
