#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 * 100;
long long m, minj, id;
pair<int, int> c[10], j[10];
bool l;
int main() {
  cin >> m;
  minj = m + 10;
  for (int i = 1; i <= 4; i++) {
    cin >> c[i].first >> j[i].first >> c[i].second >> j[i].second;
    int x =
        min((c[i].first + c[i].second),
            min((c[i].first + j[i].second),
                min((j[i].first + c[i].second), (j[i].first + j[i].second))));
    if (x <= minj) {
      minj = x;
      id = i;
    }
  }
  if (minj > m)
    cout << "-1" << endl;
  else {
    cout << id << " ";
    if (j[id].first + j[id].second <= m)
      cout << j[id].first << " " << m - j[id].first << endl;
    else {
      if (c[id].first + j[id].second <= m)
        cout << c[id].first << " " << m - c[id].first << endl;
      else {
        if (j[id].first + c[id].second <= m)
          cout << j[id].first << " " << m - j[id].first << endl;
        else if (c[id].first + c[id].second <= m)
          cout << c[id].first << " " << m - c[id].first << endl;
      }
    }
  }
  return 0;
}
