#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
  int n;
  cin >> n;
  int c1, b1, c2, b2;
  for (int i = 0; i < 4; ++i) {
    cin >> c1 >> b1 >> c2 >> b2;
    int g1 = min(c1, b1);
    int g2 = min(c2, b2);
    if (g1 + g2 <= n) {
      cout << i + 1 << ' ' << g1 << ' ' << n - g1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
