#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define MAX 50000
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector 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(a.norm()<b.norm())return -2;
  return 0;
}

typedef vector<vector<int> > Graph;
typedef pair<double,int> P;

int n;
vector<Segment> vs,va,vb;

bool check(Segment s){
  for(int i=0;i<vb.size();i++){
    if(ccw(s.p1,s.p2,vb[i].p1)==0){
      Vector v1=(s.p1-vb[i].p1),v2=(vb[i].p2-vb[i].p1);
      double r=acos(dot(v1,v2)/(abs(v1)*abs(v2)))*180/pi;
      if(90-r<eps)return false;
    }
    if(ccw(s.p1,s.p2,vb[i].p2)==0){
      Vector v1=(s.p1-vb[i].p2),v2=(vb[i].p1-vb[i].p2);
      double r=acos(dot(v1,v2)/(abs(v1)*abs(v2)))*180/pi;
      if(90-r<eps)return false;
    }
  }
  return true;
}

Graph SegmentArrangement(vector<Segment> v,vector<Point> &ps){
  for(int i=0;i<v.size();i++){
    ps.push_back(v[i].p1);
    ps.push_back(v[i].p2);
  }
  sort(ps.begin(),ps.end());
  ps.erase(unique(ps.begin(),ps.end()),ps.end());
  Graph g(ps.size());
  for(int i=0;i<v.size();i++){
    vector<pair<double,int> > list;
    for(int j=0;j<ps.size();j++)
      if(ccw(v[i].p1,v[i].p2,ps[j])==0)
        list.push_back(mp(norm(v[i].p1-ps[j]),j));
    sort(list.begin(),list.end());
    for(int j=0;j<list.size()-1;j++){
      int a=list[j].s,b=list[j+1].s;
      if(check(Segment(ps[a],ps[b])))g[a].push_back(b);
      if(check(Segment(ps[b],ps[a])))g[b].push_back(a);
    }
  }
  return g;
}

Graph g;
vector<Point> vp;
int a=-1,b=-1;
Point s,t;

void init(){
  vs.clear();va.clear();vb.clear();vp.clear();
}

void dijkstra(){
  double d[MAX];
  int p[MAX];
  fill(d,d+MAX,inf);
  fill(p,p+MAX,-1);
  priority_queue<P,vector<P>,greater<P> > pq;
  pq.push(mp(0.0,a));
  d[a]=0.0;
  p[a]=a;

  while(pq.size()){
    P u=pq.top();
    pq.pop();
    if(d[u.s]-u.f<-eps)continue;
    for(int i=0;i<g[u.s].size();i++){
      int next=g[u.s][i];
      double dis=abs(vp[u.s]-vp[next]);
      if(u.f+dis-d[next]<-eps){
        d[next]=u.f+dis;
        p[next]=u.s;
        pq.push(mp(u.f+dis,next));
      }
    }
  }
  if(p[b]==-1){
    cout<<-1<<endl;
    return;
  }
  vector<Point> ans;
  int now=b;
  while(p[now]!=now){
    ans.push_back(vp[now]);
    now=p[now];
  }
  ans.push_back(vp[now]);
  reverse(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++)cout<<ans[i].x<<" "<<ans[i].y<<endl;
  cout<<0<<endl;
}

int main()
{
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    cin>>s.x>>s.y>>t.x>>t.y;
    for(int i=0;i<n;i++){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      vs.push_back(Segment(Point(a,b),Point(c,d)));
    }
    for(int i=0;i<n;i++){
      bool left=false,right=false;
      for(int j=0;j<n;j++){
        if(i==j)continue;
        if(ccw(vs[j].p1,vs[j].p2,vs[i].p1)==0)left=true;
        if(ccw(vs[j].p1,vs[j].p2,vs[i].p2)==0)right=true;
      }
      if(left && right)va.push_back(vs[i]);
      else vb.push_back(vs[i]);
    }
    g=SegmentArrangement(va,vp);
    for(int i=0;i<vp.size();i++){
      if(vp[i]==s)a=i;
      if(vp[i]==t)b=i;
    }
    dijkstra();
  }
  return 0;
}

Measured memory_bytes: 2024