#include <bits/stdc++.h>
using namespace std;
int main() {
  long mon;
  long gua[4][8];
  cin >> mon;
  for (int post = 0; post < 4; post++) {
    for (int guard = 0; guard < 4; guard++) {
      cin >> gua[post][guard];
    }
  }
  for (int post = 0; post < 4; post++) {
    gua[post][4] = gua[post][0] + gua[post][2];
    gua[post][5] = gua[post][0] + gua[post][3];
    gua[post][6] = gua[post][1] + gua[post][2];
    gua[post][7] = gua[post][1] + gua[post][3];
  }
  for (int post = 0; post < 4; post++) {
    for (int pri = 4; pri < 8; pri++) {
      if (gua[post][pri] == mon) {
        cout << (post + 1) << " ";
        if (pri == 4) {
          cout << gua[post][0] << " " << gua[post][2];
        } else if (pri == 5) {
          cout << gua[post][0] << " " << gua[post][3];
        } else if (pri == 6) {
          cout << gua[post][1] << " " << gua[post][2];
        } else if (pri == 7) {
          cout << gua[post][1] << " " << gua[post][3];
        }
        return 0;
      } else if (gua[post][pri] < mon) {
        cout << (post + 1) << " ";
        if (pri == 4) {
          cout << gua[post][0] << " " << (mon - gua[post][0]);
        } else if (pri == 5) {
          cout << gua[post][0] << " " << (mon - gua[post][0]);
        } else if (pri == 6) {
          cout << gua[post][1] << " " << (mon - gua[post][1]);
        } else if (pri == 7) {
          cout << gua[post][1] << " " << (mon - gua[post][1]);
        }
        return 0;
      }
    }
  }
  for (int post = 0; post < 4; post++) {
    for (int pri = 4; pri < 7; pri++) {
    }
  }
  cout << "-1";
  return 0;
}
