#include <bits/stdc++.h>
using namespace std;
template <typename T>
void to_min(T &_x, const T &_y) {
  _x = min(_x, _y);
}
template <typename T>
void to_max(T &_x, const T &_y) {
  _x = max(_x, _y);
}
int n;
int a[4][4];
void input() {
  cin >> n;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> a[i][j];
    }
  }
}
void solve() {
  for (int i = 0; i < 4; i++) {
    int x = min(a[i][0], a[i][1]) + min(a[i][2], a[i][3]);
    if (x <= n) {
      cout << i + 1 << " " << min(a[i][0], a[i][1]) << " "
           << n - min(a[i][0], a[i][1]) << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}
int main() {
  input();
  solve();
  return 0;
}
