#include <bits/stdc++.h>
int main() {
  int n, t, ch = 0;
  scanf("%d", &n);
  int arr[4][4];
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      scanf("%d", &arr[i][j]);
    }
  }
  for (int i = 0; i < 4; i++) {
    t = n - arr[i][0];
    if (t >= arr[i][2] || t >= arr[i][3]) {
      printf("%d %d %d\n", i + 1, arr[i][0], t);
      ch = 1;
      break;
    }
    t = n - arr[i][1];
    if (t >= arr[i][2] || t >= arr[i][3]) {
      printf("%d %d %d\n", i + 1, arr[i][1], t);
      ch = 1;
      break;
    }
    t = n - arr[i][2];
    if (t >= arr[i][0] || t >= arr[i][1]) {
      printf("%d %d %d\n", i + 1, arr[i][2], t);
      ch = 1;
      break;
    }
    t = n - arr[i][3];
    if (t >= arr[i][0] || t >= arr[i][1]) {
      printf("%d %d %d\n", i + 1, arr[i][3], t);
      ch = 1;
      break;
    }
  }
  if (ch == 0) printf("-1\n");
  return 0;
}
