#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    int n, a, b, c, d;
    cin >> n;
    vector<pair<int, int>> v, x;
    for (int i = int(0); i < int(4); i++) {
      cin >> a >> b >> c >> d;
      x.push_back({min(a, b) + min(c, d), i});
      v.push_back({min(a, b), min(c, d)});
    }
    sort(x.begin(), x.end());
    if (x[0].first > n)
      cout << -1;
    else {
      cout << x[0].second + 1 << " " << v[x[0].second].first << " "
           << n - v[x[0].second].first;
    }
  }
}
