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