#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[4][4], total = 0;
  cin >> total;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < 4; i++) {
    if (min(arr[i][0], arr[i][1]) + min(arr[i][2], arr[i][3]) <= total) {
      cout << i + 1 << " " << min(arr[i][0], arr[i][1]) << " "
           << total - min(arr[i][0], arr[i][1]);
      return 0;
    }
  }
  cout << -1;
  return 0;
}
