#include <bits/stdc++.h>
using namespace std;
int a[5][5], i, j, l, n, m, mx, mn, txa, o, h, c, r, x[5], y[5],
    ans = 1000000020, k, sum, d, p;
int main() {
  scanf("%d", &n);
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < 4; i++) {
    x[i] = a[i][0] + a[i][2];
    y[i] = a[i][1] + a[i][3];
  }
  for (i = 0; i < 4; i++) {
    if ((a[i][0] + a[i][2]) <= n || a[i][0] + a[i][3] <= n) {
      cout << i + 1 << " " << a[i][0] << " " << n - a[i][0];
      return 0;
    }
    if ((a[i][1] + a[i][2]) <= n || a[i][1] + a[i][3] <= n) {
      cout << i + 1 << " " << a[i][1] << " " << n - a[i][1];
      return 0;
    }
  }
  cout << -1;
}
