#include <bits/stdc++.h>
using namespace std;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long vec = 2; vec * vec <= 1000000; vec++) {
    if (prime[vec] == true) {
      for (long long dd = vec * 2; dd <= 1000000; dd += vec) prime[dd] = false;
    }
  }
}
long long gcd(long long aa, long long id2) {
  if (aa == 0) {
    return id2;
  } else
    return gcd(aa % id2, id2);
}
struct vect {
  struct vect *foll;
  long long calc;
  struct vect *succ;
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = min(a, b), y = min(c, d);
    if (x + y <= n) {
      cout << i + 1 << " " << x << " " << n - x;
      return 0;
    }
  }
  cout << -1;
}
