#include <bits/stdc++.h>
using std::cin;
using std::cout;
bool Can(int N, const int* vahta, int* result1, int* result2) {
  int a = std::min(vahta[0], vahta[1]);
  int b = std::min(vahta[2], vahta[3]);
  if (a + b > N) {
    return false;
  }
  if (a < b) {
    *result1 = a;
    *result2 = N - a;
  } else {
    *result2 = b;
    *result1 = N - b;
  }
  return true;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  int vahts[4][4];
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      cin >> vahts[i][j];
    }
  }
  for (int i = 0; i < 4; ++i) {
    int result1, result2;
    if (Can(N, vahts[i], &result1, &result2)) {
      cout << i + 1 << ' ' << result1 << ' ' << result2 << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
