#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c, d;
  cin >> n;
  for (int i = 0; i < 4; i++) {
    cin >> a >> b >> c >> d;
    if (a + c <= n) {
      if (a < c)
        cout << i + 1 << " " << a << " " << n - a;
      else
        cout << i + 1 << " " << n - c << " " << c;
      return 0;
    } else if (a + d <= n) {
      if (a < d)
        cout << i + 1 << " " << a << " " << n - a;
      else
        cout << i + 1 << " " << n - d << " " << d;
      return 0;
    } else if (b + c <= n) {
      if (b < c)
        cout << i + 1 << " " << b << " " << n - b;
      else
        cout << i + 1 << " " << n - c << " " << c;
      return 0;
    } else if (d + b <= n) {
      if (d < b)
        cout << i + 1 << " " << n - d << " " << d;
      else
        cout << i + 1 << " " << b << " " << n - b;
      return 0;
    }
  }
  cout << -1;
}
