#include <bits/stdc++.h>
using namespace std;
long long n, m, j, b, i, s, a, f;
int main() {
  cin >> n;
  for (i = 0; i < 4; i++) {
    cin >> m >> j >> b >> s;
    if (min(m, j) + min(b, s) <= n) {
      j = min(m, j);
      f = n - j;
      cout << i + 1 << " " << j << " " << f;
      return 0;
    }
  }
  cout << -1;
}
