#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, f = 0;
  ;
  cin >> n;
  long long int a[4][4];
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < 4; i++) {
    if (a[i][0] + a[i][2] <= n) {
      cout << i + 1 << " " << a[i][0] << " " << n - a[i][0] << endl;
      f = 1;
      break;
    } else if (a[i][0] + a[i][3] <= n) {
      cout << i + 1 << " " << a[i][0] << " " << n - a[i][0] << endl;
      f = 1;
      break;
    } else if (a[i][1] + a[i][2] <= n) {
      cout << i + 1 << " " << a[i][1] << " " << n - a[i][1] << endl;
      f = 1;
      break;
    } else if (a[i][1] + a[i][3] <= n) {
      cout << i + 1 << " " << a[i][1] << " " << n - a[i][1] << endl;
      f = 1;
      break;
    }
  }
  if (f == 0) cout << "-1" << endl;
  return 0;
}
