#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0, j = 0, cs = 0, in;
  int n;
  cin >> n;
  int c1 = -1, c2 = -1, g = -1;
  for (i = 0; i < 4; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = min(a, b), y = min(c, d);
    if (x + y <= n) c1 = x, c2 = n - x, g = i;
  }
  if (c1 == -1)
    cout << -1 << "\n";
  else
    cout << g + 1 << " " << c1 << " " << c2 << "\n";
  return 0;
}
