#include <bits/stdc++.h>
using namespace std;
struct pair_hash {
  template <class T1, class T2>
  std::size_t operator()(std::pair<T1, T2> const &pair) const {
    std::size_t h1 = std::hash<T1>()(pair.first);
    std::size_t h2 = std::hash<T2>()(pair.second);
    return h1 ^ h2;
  }
};
unsigned long long max(unsigned long long a[], unsigned long long b[]) {
  unsigned long long r(*a);
  unsigned long long *k = a;
  while (k != b) {
    r = (r > (*k)) ? r : (*k);
    k++;
  }
  return r;
}
unsigned long long min(unsigned long long a[], unsigned long long b[]) {
  unsigned long long r(*a);
  unsigned long long *k = a;
  while (k != b) {
    r = (r < (*k)) ? r : (*k);
    k++;
  }
  return r;
}
void sieve(bool prime[], int n) {
  memset(prime, true, sizeof(bool) * n);
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
template <typename T>
bool compair(pair<T, T> a, pair<T, T> b) {
  return a.second < b.second;
}
bool isPalindrome(string a) {
  if (a.size() == 0) return true;
  long long n = a.size();
  for (long long i(0); i < n / 2; i++)
    if (a[i] != a[n - i - 1]) return false;
  return true;
}
void solve() {
  int n, a, b;
  cin >> n;
  for (long long i(0); i < 4; i++) {
    cin >> a >> b;
    int k1 = min(a, b);
    cin >> a >> b;
    int k2 = min(a, b);
    if ((k1 + k2) <= n) {
      cout << i + 1 << ' ' << n - k2 << ' ' << k2;
      return;
    }
  }
  cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  { solve(); }
  return 0;
}
