#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 2e9;
const long long N = 1e6 + 2;
const long long MAX = 2e5 + 2;
const long double EPS = 1e-8;
long long f(long long x) { return x * (x + 1) / 2; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (long long i = 0; i < 4; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (min(a, b) + min(c, d) <= n) {
      cout << i + 1 << " " << min(a, b) << " " << n - min(a, b);
      return 0;
    }
  }
  cout << -1;
}
