#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
int n, a[4][2];
inline void input() {
  cin >> n;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 2; j++) {
      int x, y;
      cin >> x >> y;
      a[i][j] = min(x, y);
    }
}
inline void solve() {
  for (int i = 0; i < 4; i++) {
    if (a[i][0] + a[i][1] <= n) {
      if (n > a[i][0] + a[i][1]) a[i][0] += n - (a[i][0] + a[i][1]);
      cout << i + 1 << ' ' << a[i][0] << ' ' << a[i][1];
      return;
    }
  }
  cout << -1;
}
int main() {
  input();
  solve();
  return 0;
}
