#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  int A[5];
  for (int i = 0; i < 4; ++i) {
    for (int i = 0; i < 4; ++i) cin >> A[i];
    bool f = 0;
    for (int a = 0; a < 2; ++a)
      for (int b = 2; b < 4; ++b)
        if (A[a] + A[b] <= n) {
          cout << i + 1 << " " << A[a] << " " << n - A[a] << "\n";
          return 0;
        }
  }
  cout << -1 << "\n";
  return 0;
}
