#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const int INF = 1<<29;
const double PI = acos(-1);
typedef complex<double> P;

namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void dijkstra(const Graph &g, int s,
                  vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(ALL(path));
  return path;
}

double ang(P a, P b) {        // ツベツクツトツδ仰つつゥツづァツづ敖つスツベツクツトツδ仰つつづ個角ツ度ツづ個計ツ算[0,2pi]
  double ret = arg(b)-arg(a);
  return (ret>=0) ? ret : ret + 2*PI;
}
double ang2(P a, P b) {
  return min(ang(a,b), ang(b,a));
}


int main() {
  int n;
  while(cin>>n, n) {
    int sx, sy;
    cin >> sx >> sy;
    P s(sx,sy);
    int gx, gy;
    cin >> gx >> gy;
    P t(gx, gy);
    vector<L> ls;
    REP(i, n) {
      int x1,y1,x2,y2;
      cin >> x1 >>y1 >> x2 >> y2;
      P p1(x1,y1), p2(x2,y2);
      ls.push_back(L(p1, p2));
    }
    vector<L> edges;
    vector<L> arrow;
    REP(i, n) {
      bool f1 = 0, f2 = 0;
      REP(j, n) {
        if (i == j) continue;
        if (intersectSP(ls[j], ls[i][0])) f1 = 1;
        if (intersectSP(ls[j], ls[i][1])) f2 = 1;
      }
      if (f1 && f2) {
        edges.push_back(ls[i]);
      } else {
        arrow.push_back(ls[i]);
      }
    }
    vector<L> tmp;
    map<P, int> mp;
    int size = 0;
    vector<P> pos;
    
    REP(i, edges.size()) {
      set<P> se;
      se.insert(edges[i][0]);
      se.insert(edges[i][1]);
      REP(j, edges.size()) {
        if (i == j) continue;
        if (intersectSS(edges[i], edges[j]))
          se.insert(crosspoint(edges[i], edges[j]));
      }
      FOR(it, se) {
        if (mp.count(*it) == 0) {
          pos.push_back(*it);
          mp[*it] = size++;
        }
        set<P>::iterator jt = it;
        jt++;
        if (jt == se.end()) break;
        tmp.push_back(L(*it, *jt));
      }
    }
    edges = tmp;

    //cout << size << endl;
    Graph g(size);
    REP(i, edges.size()) {
      P p1 = edges[i][0], p2 = edges[i][1];
      bool f1 = 0, f2 = 0;
      //cout << p1 << " " << p2 << endl;
      REP(j, arrow.size()) {
        P q1 = arrow[j][0], q2 = arrow[j][1];
        if (intersectSP(edges[i], q2)) swap(q1, q2);
        if (intersectSP(edges[i], q1)) {
          if (p1 == q1 || p2 == q1) continue;
          double angle = ang2(p2-p1, q2-q1);
          //cout << "!" << q1 << " "  << q2 << endl;
          if (abs(angle - PI/2) < EPS) {
            // ツづつソツづァツ古シツつォツづ可づ            f1 = 1;
            f2 = 1;
          } else if (angle > PI / 2) {
            f2 = 1;
          } else {
            f1 = 1;
          }
        }
      }
      if (!f1) {
        g[mp[p1]].push_back(Edge(mp[p1], mp[p2], abs(p1-p2)));
        //cout << p1 << " -> " << p2 << endl;
      }
      if (!f2) {
        g[mp[p2]].push_back(Edge(mp[p2], mp[p1], abs(p1-p2)));
        //cout << p2 << " -> " << p1 << endl;
      }
    }
    vector<int> dist, prev;
    dijkstra(g, mp[s],dist,prev);
    if (dist[mp[t]] == INF) {
      cout << -1 << endl;
    } else {
      vector<int> path = buildPath(prev, mp[t]);
      FOR(it, path) {
        printf("%d %d\n", (int)pos[*it].real(), (int)pos[*it].imag());
      }
      cout << 0 << endl;
    }
  }
}

Measured memory_bytes: 1028