#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const int MAXN = 10 + 100000;
const int INF = int(1e9);
const int m = 4;
int k, t, d;
int a[5][5], i, j, n;
void nhap() {
  scanf("%d", &n);
  for (int i = (1), _b = (m); i <= m; ++i)
    scanf("%d%d%d%d", &a[i][1], &a[i][2], &a[i][3], &a[i][4]);
}
void xuli() {}
int main() {
  nhap();
  xuli();
  for (int i = (1), _b = (m); i <= m; ++i) {
    t = min(a[i][1], a[i][2]);
    d = min(a[i][3], a[i][4]);
    if (n - t >= d) {
      cout << i << " " << t << " " << n - t;
      return 0;
    }
  }
  printf("-1");
  return 0;
}
