#include <bits/stdc++.h>
using namespace std;
pair<int, int> a, b;
int n, i;
bool x;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i <= 4; i++) {
    cin >> a.first >> a.second >> b.first >> b.second;
    if (a.first > a.second) swap(a.first, a.second);
    if (b.first > b.second) swap(b.first, b.second);
    x = true;
    if (a.first > b.first) x = false;
    if (n - min(a.first, b.first) >= max(a.first, b.first)) {
      cout << i << " ";
      if (x)
        cout << min(a.first, b.first) << " " << n - min(a.first, b.first)
             << '\n';
      else
        cout << n - min(a.first, b.first) << " " << min(a.first, b.first)
             << '\n';
      return 0;
    }
  }
  cout << "-1" << '\n';
  return 0;
}
