#include <bits/stdc++.h>
using namespace std;
long long hell = 1e9 + 7;
bool check(int num) {
  int temp = sqrt(num);
  if (temp * temp == num)
    return 1;
  else
    return 0;
}
void swap(int *a, int *b) {
  int temp = *a;
  *a = *b;
  *b = temp;
}
bool poweroftwo(int n) { return (n && (!(n & (n - 1)))); }
bool getbit(int n, int pos) {
  if ((n & (1 << pos)) == 0)
    return 0;
  else
    return 1;
}
int setbit(int n, int pos) { return ((n | (1 << pos))); }
bool primesieve(int num) {
  int ar[100001] = {0};
  ar[0] = ar[1] = 1;
  for (int i = 4; i <= 100000; i += 2) ar[i] = 1;
  for (int i = 3; i <= 100000; i += 2) {
    if (ar[i] == 0) {
      for (int j = i * i; j <= 100000; j += i) ar[j] = 1;
    }
  }
  if (ar[num] == 0)
    return true;
  else
    return false;
}
int gcd(int a, int b) {
  while (b) {
    int rem = a % b;
    a = b;
    b = rem;
  }
  return a;
}
int nfib(int n) {
  if (n == 1) return 1;
  if (n == 2) return 1;
  return nfib(n - 1) + nfib(n - 2);
}
void factorsieve(int n) {
  int ar[1001] = {0};
  ar[1] = 1;
  for (int i = 2; i < 1001; i++) ar[i] = i;
  for (int i = 4; i <= 1001; i += 2) ar[i] = 2;
  for (int i = 3; i * i <= 1001; i++) {
    if (ar[i] == i) {
      for (int j = i * i; j <= 1001; j += i) {
        if (ar[j] == j) ar[j] = i;
      }
    }
  }
  while (n != 1) {
    cout << ar[n] << " ";
    n = n / ar[n];
  }
}
int first(int ar[], int n, int i, int key) {
  if (i == n) return -1;
  if (ar[i] == key) return i;
  return first(ar, n, i + 1, key);
}
int last(int ar[], int n, int i, int key) {
  if (i == n) return -1;
  if (ar[i] == key) return i;
  return last(ar, n, i - 1, key);
}
int main() {
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    pair<int, int> pr[4];
    for (int i = 0; i < 4; i++) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      pr[i].first = min(a, b);
      pr[i].second = min(c, d);
    }
    int f = 0;
    for (int i = 0; i < 4; i++) {
      if (n >= pr[i].first + pr[i].second) {
        cout << i + 1 << " " << pr[i].first << " " << n - pr[i].first;
        f = 1;
        break;
      }
    }
    if (f == 0) cout << -1;
  }
  return 0;
}
