#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-7;
const double INF=1e77;

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
point<T> operator*(T c,const point<T> &a){ return (point<T>){c*a.x,c*a.y}; }

bool operator<(const point<double> &a,const point<double> &b){
	return a.x+EPS<b.x || abs(a.x-b.x)<EPS && a.y+EPS<b.y;
}
bool operator==(const point<double> &a,const point<double> &b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}

template<class T>
struct line{ point<T> a,b; };

template<class T>
struct segment{
	point<T> a,b;
	operator line<T>()const{ return (line<T>){a,b}; }
};

template<class T>
T dot(const point<T> &a,const point<T> &b){ return a.x*b.x+a.y*b.y; }

template<class T>
T cross(const point<T> &a,const point<T> &b){ return a.x*b.y-a.y*b.x; }

enum {CCW=1,CW=-1,ON=0};
int ccw(const point<double> &a,const point<double> &b,const point<double> &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

template<class T>
double dist(const point<T> &a,const point<T> &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

bool cover(const segment<double> &S,const point<double> &p){
	return dist(S.a,p)+dist(p,S.b)<dist(S.a,S.b)+EPS;
}

bool intersect(const segment<double> &S1,const segment<double> &S2){
	if(max(S1.a.x,S1.b.x)+EPS<min(S2.a.x,S2.b.x)
	|| max(S1.a.y,S1.b.y)+EPS<min(S2.a.y,S2.b.y)
	|| max(S2.a.x,S2.b.x)+EPS<min(S1.a.x,S1.b.x)
	|| max(S2.a.y,S2.b.y)+EPS<min(S1.a.y,S1.b.y)) return false;
	return ccw(S1.a,S1.b,S2.a)*ccw(S1.a,S1.b,S2.b)<=0
		&& ccw(S2.a,S2.b,S1.a)*ccw(S2.a,S2.b,S1.b)<=0;
}

point<double> get_intersect(const line<double> &L1,const line<double> &L2){
	double a1=cross(L1.b-L1.a,L2.b-L2.a);
	double a2=cross(L1.b-L1.a,L1.b-L2.a);
	if(abs(a1)<EPS) return L1.a;
	return L2.a+a2/a1*(L2.b-L2.a);
}

void arrangement(const vector< segment<double> > &S,vector< point<double> > &P,vector<int> *G){
	int n=S.size();
	P.clear();
	rep(i,n){
		P.push_back(S[i].a);
		P.push_back(S[i].b);
		rep(j,i) if(intersect(S[i],S[j])) P.push_back(get_intersect(S[i],S[j]));
	}
	sort(P.begin(),P.end());
	P.erase(unique(P.begin(),P.end()),P.end());

	rep(i,n){
		vector<int> on;
		rep(u,P.size()) if(cover(S[i],P[u])) on.push_back(u);
		rep(j,(int)on.size()-1){
			int u=on[j],v=on[j+1];
			G[u].push_back(v);
			G[v].push_back(u);
		}
	}
}

bool can_pass(const point<double> &s,const point<double> &t,const vector< segment<double> > &sign){
	int n=sign.size();
	segment<double> R={s,t};
	rep(i,n){
		segment<double> S=sign[i];
		if(cover(R,S.a) && dot(s-S.a,S.b-S.a)<=0) return false;
		if(cover(R,S.b) && dot(s-S.b,S.a-S.b)<=0) return false;
	}
	return true;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		point<double> s,t; scanf("%lf%lf%lf%lf",&s.x,&s.y,&t.x,&t.y);
		segment<double> S[200];
		rep(i,n) scanf("%lf%lf%lf%lf",&S[i].a.x,&S[i].a.y,&S[i].b.x,&S[i].b.y);

		vector< segment<double> > road,sign;
		rep(i,n){
			bool ok1=false,ok2=false;
			rep(j,n) if(i!=j) {
				if(cover(S[j],S[i].a)) ok1=true;
				if(cover(S[j],S[i].b)) ok2=true;
			}
			if(ok1&&ok2) road.push_back(S[i]);
			else         sign.push_back(S[i]);
		}

		vector< point<double> > 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 t_id=find(P.begin(),P.end(),t)-P.begin();

		int path[400];
		double d[400];
		rep(u,N) 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;

			rep(i,G[u].size()){
				int v=G[u][i];
				double cost=sqrt((P[u].x-P[v].x)*(P[u].x-P[v].x)+(P[u].y-P[v].y)*(P[u].y-P[v].y));
				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[t_id]>INF/2) puts("-1");
		else{
			vector<int> ans(1,t_id);
			int u=t_id;
			while(u!=s_id) u=path[u], ans.push_back(u);
			reverse(ans.begin(),ans.end());
			rep(i,ans.size()) printf("%.0f %.0f\n",P[ans[i]].x,P[ans[i]].y);
			puts("0");
		}
	}

	return 0;
}

Measured memory_bytes: 1192