#include <bits/stdc++.h>
using namespace std;
bool isPos(int idx, int n, int a, int b, int c, int d) {
  if (a + c <= n || a + d <= n) {
    cout << idx << " " << a << " " << n - a << endl;
    return true;
  } else if (b + d <= n || b + c <= n) {
    cout << idx << " " << b << " " << n - b << endl;
    return true;
  }
  return false;
}
int main() {
  int n;
  int ar[4][4];
  cin >> n;
  for (int i = 0; i < (4); i++)
    for (int j = 0; j < (4); j++) cin >> ar[i][j];
  for (int i = 0; i < (4); i++) {
    if (isPos(i + 1, n, ar[i][0], ar[i][1], ar[i][2], ar[i][3])) return 0;
  }
  cout << -1 << endl;
  return 0;
}
