#include <bits/stdc++.h>
using namespace std;
bool check(int arr[], int n, int &ans1, int &ans2) {
  int a, b;
  a = min(arr[0], arr[1]);
  b = min(arr[2], arr[3]);
  n = n - a;
  if (n < b) {
    return false;
  } else {
    ans1 = a;
    ans2 = n;
    return true;
  }
}
int main() {
  int n;
  int ans1, ans2;
  cin >> n;
  int arr[16];
  for (int i = 0; i < 16; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < 4; i++) {
    if (check(arr + sizeof(int) * i, n, ans1, ans2)) {
      cout << i + 1 << ' ' << ans1 << ' ' << ans2 << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
