#include <bits/stdc++.h>
using namespace std;
int kep[10][10];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int flag = 0;
    int ans = n;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) scanf("%d", &kep[i][j]);
    }
    for (int i = 0; i < 4; i++) {
      ans = n;
      int a, b;
      if (kep[i][0] < kep[i][1]) {
        ans -= kep[i][0];
        a = kep[i][0];
      } else {
        ans -= kep[i][1];
        a = kep[i][1];
      }
      if (kep[i][2] < kep[i][3]) {
        ans -= kep[i][2];
        b = kep[i][2];
      } else {
        ans -= kep[i][3];
        b = kep[i][3];
      }
      if (ans >= 0) {
        flag = 1;
        printf("%d %d %d\n", i + 1, a, n - a);
        break;
      }
    }
    if (!flag) printf("-1\n");
  }
  return 0;
}
