#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
int main() {
  int n, i, j;
  cin >> n;
  int p, q, gift1, gift2;
  int a[4][4];
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      cin >> a[i][j];
    }
    p = min(a[i][0], a[i][1]);
    q = min(a[i][2], a[i][3]);
    if (p + q > n)
      continue;
    else {
      gift1 = p;
      gift2 = n - p;
      break;
    }
  }
  if (i < 4)
    cout << i + 1 << " " << gift1 << " " << gift2 << endl;
  else
    cout << "-1" << endl;
  return 0;
}
