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