#include <bits/stdc++.h>
using namespace std;
const int INF = int(1E9 + 7);
const double EPS = 1e-6;
int main() {
  int n, p[4][4];
  bool found;
  int f, s;
  while (cin >> n) {
    found = false;
    for (int i = (0); (i) < int(4); ++i)
      for (int j = (0); (j) < int(4); ++j) cin >> p[i][j];
    for (int i = (0); (i) < int(4); ++i) {
      for (int j = (0); (j) < int(2); ++j)
        for (int h = (2); (h) < int(4); ++h) {
          if (p[i][j] + p[i][h] <= n) {
            f = p[i][j];
            s = p[i][h];
            if (f + s <= n) f += n - (f + s);
            found = true;
            printf("%d %d %d\n", i + 1, f, s);
            goto done;
          }
        }
    }
  done:
    if (!found) puts("-1");
  }
  return 0;
}
