#include <bits/stdc++.h>
using namespace std;
int n, a[4][4];
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++) {
    int x = min(a[i][0], a[i][1]);
    int y = min(a[i][2], a[i][3]);
    if (n >= x + y) {
      if (x == a[i][0]) {
        printf("%d %d %d\n", i + 1, x, n - x);
      } else {
        printf("%d %d %d\n", i + 1, n - y, y);
      }
      return 0;
    }
  }
  puts("-1");
  return 0;
}
