#include <bits/stdc++.h>
using namespace std;

typedef complex<double> P;

const double inf = 1e10;
const double eps = 1e-8;

bool equals(double a, double b) {
  return abs(a - b) < eps;
}

namespace std {
  bool operator < (const P &a, const P &b) {
    return ( a.real() != b.real()
             ? a.real() < b.real() : a.imag() < b.imag() );
  }
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a, b) > eps) return 1;
  if(cross(a, b) < -eps) return -1;
  if(dot(a, b) < -eps) return 2;
  if(norm(a) + eps < norm(b)) return -2;
  return 0;
}

bool isIntersect(P a1, P a2, P b1, P b2) {
  return ( ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
           ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0 );
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1) / cross(b, a);
}

struct Edge { int v; double w; int rev; };
typedef vector<vector<Edge> > Graph;

Graph segmentArrangement(const vector<P> &s1, const vector<P> &s2,
                         vector<P> &ps) {
  int m = s1.size();
  for(int i = 0; i < m; ++i) {
    ps.push_back(s1[i]);
    ps.push_back(s2[i]);
    for(int j = i+1; j < m; ++j) {
      if(equals(cross(s1[i] - s2[i], s1[j] - s2[j]), 0.0)) continue;
      if(!isIntersect(s1[i], s2[i], s1[j], s2[j])) continue;
      ps.push_back(getCrossP(s1[i], s2[i], s1[j], s2[j]));
    }
  }
  sort(ps.begin(), ps.end());
  ps.erase(unique(ps.begin(), ps.end()), ps.end());

  int n = ps.size();
  Graph g(n);
  for(int i = 0; i< m; ++i) {
    vector<pair<double, int> > v;
    for(int j = 0; j < n; ++j) {
      if(ps[j] == s1[i] || ps[j] == s2[i] ||
         !ccw(s1[i], s2[i], ps[j])) {
        v.push_back(make_pair(norm(s1[i] - ps[j]), j));
      }
    }
    sort(v.begin(), v.end());
    for(int j = 0; j+1 < v.size(); ++j) {
      int a = v[j].second, b = v[j+1].second;
      double w = abs(ps[a] - ps[b]);
      g[a].push_back((Edge){b, w, g[b].size()});
      g[b].push_back((Edge){a, w, g[a].size()-1});
    }
  }
  return g;
}

typedef pair<double, int> Pair;

int n;
P s, g;
vector<P> s1, s2, ps;
vector<int> isSign;
int N, src, dst;
Graph G;

int main() {
  while(cin >> n && n) {
    cin >> s.real() >> s.imag();
    cin >> g.real() >> g.imag();
    s1.resize(n);
    s2.resize(n);
    for(int i = 0; i < n; ++i) {
      cin >> s1[i].real() >> s1[i].imag()
          >> s2[i].real() >> s2[i].imag();
    }

    ps.clear();
    G = segmentArrangement(s1, s2, ps);
    N = G.size();
    src = find(ps.begin(), ps.end(), s) - ps.begin();
    dst = find(ps.begin(), ps.end(), g) - ps.begin();

    isSign = vector<int>(ps.size());
    for(int i = 0; i < N; ++i) {
      if(G[i].size() == 1) {
        int a = i;
        int b = G[a][0].v;
        isSign[b] = true;
        int pc = 0;
        int c = G[b][pc].v;
        while(G[c].size() == 1) c = G[b][++pc].v;
        int pd = G[b].size()-1;
        int d = G[b][pd].v;
        while(G[d].size() == 1) d = G[b][--pd].v;
        double s = dot(ps[a] - ps[b], ps[c] - ps[b]);
        if(s >= 0.0) G[b][pc].w = inf;
        if(s <= 0.0) G[b][pd].w = inf;
        G[b][G[a][0].rev].w = inf;
      }
    }

    vector<double> cost(N, inf);
    priority_queue<Pair, vector<Pair>, greater<Pair> > que;
    vector<int> prev(N, -1);
    cost[src] = 0.0;
    que.push(make_pair(0.0, src));
    while(que.size()) {
      const Pair s = que.top(); que.pop();
      if(cost[s.second] < s.first) continue;
      if(s.second == dst) break;
      for(int i = 0; i < G[s.second].size(); ++i) {
        if(G[s.second][i].w == inf) continue;
        const Pair t(s.first + G[s.second][i].w, G[s.second][i].v);
        if(cost[t.second] <= t.first) continue;
        cost[t.second] = t.first;
        prev[t.second] = s.second;
        que.push(t);
      }
    }

    if(cost[dst] == inf) {
      cout << -1 << endl;
    } else {
      vector<int> vs;
      for(int v = dst; v != -1; v = prev[v]) {
        vs.push_back(v);
      }
      for(int i = vs.size()-1; i >= 0; --i) {
        if(isSign[vs[i]]) continue;
        cout << (int)ps[vs[i]].real() << " " 
             << (int)ps[vs[i]].imag() << endl;
      }
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1364