#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int arr[5][5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= 4; j++) cin >> arr[i][j];
  for (int i = 1; i <= 4; i++)
    for (int j1 = 1; j1 <= 2; j1++)
      for (int j2 = 3; j2 <= 4; j2++)
        if (arr[i][j1] + arr[i][j2] <= n) {
          cout << i << " " << arr[i][j1] << " "
               << arr[i][j2] + (n - (arr[i][j1] + arr[i][j2]));
          return 0;
        }
  cout << "-1";
  return 0;
}
