#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool is_vowel(char c) {
  c = tolower(c);
  return c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u' || c == 'y';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + c <= n || a + d <= n) {
      cout << i + 1 << ' ' << a << ' ' << n - a;
      return 0;
    }
    if (b + c <= n || b + d <= n) {
      cout << i + 1 << ' ' << b << ' ' << n - b;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
