#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print2dvector(vector<vector<T> > v) {
  cout << "A 2d vector:" << endl;
  int a = v.size();
  int b = v[0].size();
  if (a <= 15 && b <= 15) {
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << endl;
    }
  }
  if (a > 15 && b > 15) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << "   "
           << ".   .   ." << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]
           << setw(4) << v[i][b - 1] << endl;
    }
    for (int i = 0; i < 15; i++) {
      cout << setw(4) << '.';
    }
    cout << endl;
    for (int i = a - 3; i < a; i++) {
      for (int j = 0; j < 9; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << "   "
           << ".   .   ." << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]
           << setw(4) << v[i][b - 1] << endl;
    }
  }
  if (a > 15) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < b; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << endl;
    }
    for (int i = 0; i < b; i++) {
      cout << setw(4) << '.';
    }
    cout << endl;
    for (int i = a - 3; i < a; i++) {
      for (int j = 0; j < b; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << endl;
    }
  }
  if (b > 15) {
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < 9; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << "   "
           << ".   .   ." << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]
           << setw(4) << v[i][b - 1] << endl;
    }
  }
}
template <typename T>
void printvector(vector<T> v) {
  cout << "A 1d vector:" << endl;
  int a = v.size();
  if (a <= 15) {
    for (int i = 0; i < a; i++) {
      cout << setw(4) << v[i];
    }
  } else {
    for (int i = 0; i < 9; i++) {
      cout << setw(4) << v[i];
    }
    cout << "   "
         << ".   .   ." << setw(4) << v[a - 3] << setw(4) << v[a - 2] << setw(4)
         << v[a - 1];
  }
  cout << endl;
}
int n;
vector<vector<int> > v(4, vector<int>(4, 0));
int main() {
  cin >> n;
  int a, b, c, d;
  for (int i = 0; i < 4; i++) {
    cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
  }
  bool flag = false;
  for (int i = 0; i < 4; i++) {
    if (min(v[i][0], v[i][1]) + min(v[i][2], v[i][3]) <= n) {
      cout << i + 1 << " " << min(v[i][0], v[i][1]) << " "
           << n - min(v[i][0], v[i][1]) << endl;
      flag = true;
      break;
    }
  }
  if (flag == false) {
    cout << -1 << endl;
  }
  return 0;
}
