#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
  int n, a[5][5];
  cin >> n;
  int ans1 = -1, ans2, ans3;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 4; j++) cin >> a[i][j];
    int mi = min(a[i][1], a[i][2]);
    int mi2 = min(a[i][3], a[i][4]);
    if (n >= mi + mi2) {
      cout << i << " " << mi << " " << n - mi << endl;
      return;
    }
  }
  cout << ans1 << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
