#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>

using namespace std;
typedef complex<double> Point;
struct Segment{ Point p1, p2; };
typedef Segment Line;
const double EPS = 1e-7;
const double INF = 1e77;

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

double getDistance(Point a, Point b){
  return abs(a - b);
}

bool isCover(Segment s, Point p){
  return getDistance(s.p1, p) + getDistance(p, s.p2) < getDistance(s.p1, s.p2) + EPS;
}

double dot(Point a, Point b){
  return real(conj(a) * b);
}

double cross(Point a, Point b){
  return imag(conj(a) * b);
}

int ccw(Point p0, Point p1, Point p2){
  Point a = p1 - p0;
  Point b = p2 - p0;
  if(cross(a, b) > EPS) return 1;
  if(cross(a, b) < -EPS) return -1;
  if(dot(a, b) < -EPS) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4){
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
          ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool isIntersect(Segment s1, Segment s2){
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point getCrossPoint(Segment s1, Segment s2){
  double a1 = cross(s1.p2 - s1.p1, s2.p2 - s2.p1);
  double a2 = cross(s1.p2 - s1.p1, s1.p2 - s2.p1);
  if(abs(a1) < EPS) return s1.p1;
  return s2.p1 + a2 / a1 * (s2.p2 - s2.p1);
}

void arrangement(const vector<Segment>& S, vector<Point>& P, vector<int>* G){
  int n = S.size();
  P.clear();
  vector<pair<double, double> > tmp;
  for(int i=0;i<n;i++){
    tmp.push_back(make_pair(S[i].p1.real(), S[i].p1.imag()));
    tmp.push_back(make_pair(S[i].p2.real(), S[i].p2.imag()));
    for(int j=0;j<i;j++){
      if(isIntersect(S[i], S[j])){
        Point t = getCrossPoint(S[i], S[j]);
        tmp.push_back(make_pair(t.real(), t.imag()));
      }
    }
  }
  sort(tmp.begin(), tmp.end());
  tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
  for(int i=0;i<tmp.size();i++) P.push_back(Point(tmp[i].first, tmp[i].second));
  for(int i=0;i<n;i++){
    vector<int> on;
    for(int u=0;u<P.size();u++){
      if(isCover(S[i], P[u])) on.push_back(u);
      for(int j=0;j<(int)on.size()-1;j++){
        int u = on[j], v = on[j+1];
        G[u].push_back(v);
        G[v].push_back(u);
      }
    }
  }
}

bool can_pass(const Point& s, const Point& t, const vector<Segment>& sign){
  int n = sign.size();
  Segment R = {s, t};
  for(int i=0;i<n;i++){
    Segment S = sign[i];
    if(isCover(R, S.p1) && dot(s - S.p1, S.p2 - S.p1) <= 0) return false;
    if(isCover(R, S.p2) && dot(s - S.p2, S.p1 - S.p2) <= 0) return false;
  }
  return true;
}

main(){
  int n;
  while(cin >> n && n){
    vector<Segment> seg;
    Point s, g;
    cin >> s.real() >> s.imag();
    cin >> g.real() >> g.imag();
    for(int i=0;i<n;i++){
      Segment in;
      cin >> in.p1.real() >> in.p1.imag() >> in.p2.real() >> in.p2.imag();
      seg.push_back(in);
    }
    vector<Segment> road, sign;
    for(int i=0;i<n;i++){
      bool f[2] = {false, false};
      for(int j=0;j<n;j++){
        if(i == j) continue;
        if(isCover(seg[j], seg[i].p1)) f[0] = true;
        if(isCover(seg[j], seg[i].p2)) f[1] = true;
      }
      if(f[0] && f[1]) road.push_back(seg[i]);
      else sign.push_back(seg[i]);
    }
    vector<Point> P;
    vector<int> G[400];
    arrangement(road, P, G);
    int N = P.size();
    int s_id = find(P.begin(), P.end(), s) - P.begin();
    int g_id = find(P.begin(), P.end(), g) - P.begin();

    int path[400];
    double d[400];
    for(int u=0;u<N;u++) d[u] = (u == s_id ? 0 : INF);
    priority_queue<pair<double, int> > Q;
    Q.push(make_pair(0, s_id));
    while(!Q.empty()){
      double d_now = -Q.top().first;
      int u = Q.top().second;
      Q.pop();
      if(d[u] < d_now - EPS) continue;
      
      for(int i=0;i<G[u].size();i++){
        int v = G[u][i];
        double cost = sqrt((P[u].real() - P[v].real()) * (P[u].real() - P[v].real()) +
                           (P[u].imag() - P[v].imag()) * (P[u].imag() - P[v].imag()));
        if(d[v] - EPS > d[u] + cost && can_pass(P[u], P[v], sign)){
          d[v] = d[u] + cost;
          path[v] = u;
          Q.push(make_pair(-d[v], v));
        }
      }
    }
    
    if(d[g_id] > INF / 2) printf("-1\n");
    else{
      vector<int> ans(1, g_id);
      int u = g_id;
      while(u != s_id) u = path[u], ans.push_back(u);
      reverse(ans.begin(), ans.end());
      for(int i=0;i<ans.size();i++){
        printf("%.0f %.0f\n", P[ans[i]].real(), P[ans[i]].imag());
      }
      printf("0\n");
    }
  }
}

Measured memory_bytes: 1444