#include <bits/stdc++.h>
using namespace std;
int a[4][4];
int main() {
  int n;
  cin >> n;
  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++) {
    int c1 = a[i][0], c2 = a[i][2];
    int j1 = a[i][1], j2 = a[i][3];
    if (c1 + c2 <= n) {
      cout << i + 1 << " " << n - c2 << " " << c2 << endl;
      return 0;
    } else if (c1 + j2 <= n) {
      cout << i + 1 << " " << n - j2 << " " << j2 << endl;
      return 0;
    } else if (j1 + c2 <= n) {
      cout << i + 1 << " " << n - c2 << " " << c2 << endl;
      return 0;
    } else if (j1 + j2 <= n) {
      cout << i + 1 << " " << n - j2 << " " << j2 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
