#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>

#define cauto const auto&

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()

#define MOD 1000000007LL
typedef pair<double,double> pdd;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = asin(0.5)*6;
typedef complex<double> P;

#define X real()
#define Y imag()

#define Curr(P,i) P[(i)%P.size()]
#define Next(P,i) P[(i+1)%P.size()]
#define Prev(P,i) P[(i+P.size()-1)%P.size()]

namespace std{
  bool operator<(const P a,const P b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}
double cross(const P a,const P b){
  return (conj(a)*b).imag();
}
double dot(const P a,const P b){
  return (conj(a)*b).real();
}
int ccw(P a,P b,P c){
  b-=a;
  c-=a;
}

struct L : public vector<P>{
  L(const P a,const P b){
    push_back(a),push_back(b);
  }
};
typedef L S;
bool isCrossSP(S a,P p){
  return abs(a[0]-p)+abs(a[1]-p)-abs(a[0]-a[1]) < EPS;
}
pdd ptopdd(P a){
	return pdd(a.real(),a.imag());
}
P pddtop(pdd a){
	return P(a.first,a.second);
}
int foo3(S a,P b,P c){
	double ab0=abs(a[0]-b);
	double ac0=abs(a[0]-c);
	double bc =abs(b-c);
	if(abs(ac0*ac0-ab0*ab0-bc*bc)<EPS){
		return 2;
	}
	if(ac0*ac0-ab0*ab0-bc*bc>EPS){
		return 0;
	}
	return 1;
}
bool operator<(P a,P b){
	if(a.X==b.X){
		return a.Y<b.Y;
	}
	return a.X<b.X;
}
void mainmain(){
	int n;
	while(cin>>n,n){
		P s,g;
		double a[4];
		rep(i,4) cin>>a[i];
		s=P(a[0],a[1]);
		g=P(a[2],a[3]);
		vector<S> v1;
		S tmp(s,g);
		rep(i,n){
			double a[4];
			rep(j,4) cin>>a[j];
			P t1=P(a[0],a[1]);
			P t2=P(a[2],a[3]);
			S tmp=S(t1,t2);
			v1.PB(tmp);
		}
		vector<S> sign,road;
		rep(i,n){
			bool f1=true;
			bool f2=true;
			rep(j,n){
				if(i==j) continue;
				if(isCrossSP(v1[j],v1[i][0])){
					f1=false;
				}
				if(isCrossSP(v1[j],v1[i][1])){
					f2=false;
				}
			}
			if(f1||f2){
				sign.PB(v1[i]);
			}
			else{
				road.PB(v1[i]);
			}
		}
		vector<S> troad;
		rep(i,road.size()){
			vector<S> tmp;
			tmp.PB(road[i]);
			rep(j,road.size()){
				if(i==j) continue;
				rep(k,tmp.size()){
					bool f=false;
					P p;
					rep(o,2){
						if(isCrossSP(tmp[k],road[j][o])){
							f=true;
							p=road[j][o];
						}
					}
					if(f&&abs(tmp[k][0]-p)>EPS&&abs(tmp[k][1]-p)>EPS){
						S tt=tmp[k];
						tmp[k]=S(tt[0],p);
						tmp.PB(S(tt[1],p));
						k--;
					}
				}
			}
			rep(j,tmp.size()){
				troad.PB(tmp[j]);
			}
		}
		road=troad;
		map<pdd,int> ma;
		vector<pii> vp;
		rep(i,road.size()){
			rep(j,2){
				pdd t=ptopdd(road[i][j]);
				if(ma.find(t)==ma.end()){
					ma[t]=0;
					vp.PB(pii(int(t.fi),int(t.se)));
					ma[t]=ma.size()-1;
				}
			}
		}
		typedef pair<int,double> pid;
		VV(pid) vv(ma.size());
		rep(i,road.size()){
			bool f[2]={true,true};
			rep(j,sign.size()){
				rep(k,2){
					if(isCrossSP(road[i],sign[j][k])){
						int aa=foo3(road[i],sign[j][k],sign[j][1-k]);
						if(aa==2){
							f[0]=f[1]=false;
						}
						if(aa==0){
							f[0]=false;
						}
						if(aa==1){
							f[1]=false;
						}
					}
				}
			}
			rep(j,2){
				if(f[j]){
					vv[ma[ptopdd(road[i][j])]].PB(pid(ma[ptopdd(road[i][1-j])],abs(road[i][0]-road[i][1])));
				}
			}
		}
		priority_queue<pair<double,pii> > pq;
		vector<pair<double,int> > ans(vp.size(),pair<double,int>(INF,-2));
		pq.push(pair<double,pii>(0.0,pii(ma[ptopdd(s)],-1)));
		while(!pq.empty()){
			pair<double,pii> top=pq.top();
			pq.pop();
			if(ans[top.se.fi].se!=-2) continue;
			ans[top.se.fi]=pair<double,int>(top.fi,top.se.se);
			rep(i,vv[top.se.fi].size()){
				if(ans[vv[top.se.fi][i].fi].se!=-2) continue;
				pq.push(pair<double,pii>(top.fi-vv[top.se.fi][i].se,pii(vv[top.se.fi][i].fi,top.se.fi)));
			}
		}
		vector<int> res;
		int pos=ma[ptopdd(g)];
		if(ans[pos].se==-2){
			cout<<-1<<endl;
			continue;
		}
		while(pos!=-1){
			res.PB(pos);
			pos=ans[pos].se;
		}
		reverse(ALL(res));
		rep(i,res.size()){
			cout<<vp[res[i]].fi<<" "<<vp[res[i]].se<<endl;
		}
		cout<<0<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1348