#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, INF = 2000000001;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
    dy[] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
const double EPS = 1e-9;
long long gcd(long long a, long long b) { return (b != 0) ? gcd(b, a % b) : a; }
long long modpow(long long a, long long x, long long m = mod) {
  int p = 1;
  while (x > 0) {
    if (x & 1 == 1) {
      p = p * a % m;
      --x;
    } else {
      x >>= 1;
      a = a * a % m;
    }
  }
  return p;
}
void z(const string& s, vector<int>& v) {
  int n = s.length();
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) v[i] = min(v[i - l], r - i + 1);
    while (i + v[i] < n && s[v[i]] == s[i + v[i]]) ++v[i];
    if (i + v[i] - 1 > r) r = (l = i) + v[i] - 1;
  }
}
bool dfs(vector<vector<string> >& states, int sx, int sy, int n) {
  bool ans = false;
  if (n == 8)
    ans = true;
  else if (states[n][sy][sx] == 'S')
    ans = false;
  else
    for (int d = 0; d < 9 && !ans; ++d) {
      int x = sx + dx[d], y = sy + dy[d];
      if (min(x, y) >= 0 && max(x, y) < 8) {
        if (states[n][y][x] == '.') {
          ans = dfs(states, x, y, n + 1);
        }
      }
    }
  return ans;
}
void _a() {
  int n;
  cin >> n;
  int x = -1, y = -1, z = -1;
  for (int i = 1; i <= 4; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + c <= n) {
      x = i;
      y = a;
      z = c;
      break;
    } else if (a + d <= n) {
      x = i;
      y = a;
      z = d;
      break;
    } else if (b + c <= n) {
      x = i;
      y = b;
      z = c;
      break;
    } else if (b + d <= n) {
      x = i;
      y = b;
      z = d;
      break;
    }
  }
  if (x == -1)
    cout << -1;
  else {
    if (y + z < n) y += n - y - z;
    cout << x << ' ' << y << ' ' << z;
  }
}
void _b() {
  int n, k;
  cin >> n >> k;
  vector<int> a(2 * n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  int sum = INF, index = -1;
  for (int i = 0; i < k; ++i) {
    int s = 0;
    for (int j = i, c = 0; c < n / k; j += k, ++c) {
      s += a[j];
    }
    if (s < sum) {
      sum = s;
      index = i;
    }
  }
  cout << index + 1;
}
class P {
 public:
  double n, d;
  P(double dd) : n(dd), d(dd - floor(n)) {}
};
class CP {
 public:
  bool operator()(const P& a, const P& b) const { return a.d < b.d; }
};
void _c() {}
void _d() {}
void _e() {}
long long gcdex(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  } else {
    long long x1, y1;
    long long g = gcdex(b % a, a, x1, y1);
    x = y1 - b / a * x1;
    y = x1;
    return g;
  }
}
int main() {
  _a();
  return 0;
}
