#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

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
// #define EPS 1e-8
// static const int INF=1<<24;
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;
  }
}
//gaiseki
double cross(const P a,const P b){
  return (conj(a)*b).imag();
}
//naiseki
double dot(const P a,const P b){
  return (conj(a)*b).real();
}
// TODO make graph (20)
int ccw(P a,P b,P c){
  b-=a;
  c-=a;
  if(cross(b,c)>0)    return +1;//counter clockwise
  if(cross(b,c)<0)    return -1;//clockwise
  if(dot(b,c)<0)      return +2;// c--a--b
  if(norm(b)<norm(c)) return -2;// a--b--c
                      return  0;// a--c--b(or b==c)
}

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);
	double t=ac0*ac0-ab0*ab0-bc*bc;
	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;
			// cout<<top.se.fi<<endl;
			// cout<<"size "<<vv[top.se.fi].size()<<endl;
			// cout<<top.fi<<" "<<top.se.fi<<" "<<top.se.se<<endl;
			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)));
			}
			// cout<<"hoge"<<endl;
		}
		// puts("hoge");
		vector<int> res;
		int pos=ma[ptopdd(g)];
		// rep(i,ans.size()){
			// cout<<i<<" "<<ans[i].fi<<" "<<ans[i].se<<endl;
		// }
		// continue;
		if(ans[pos].se==-2){
			cout<<-1<<endl;
			continue;
		}
		while(pos!=-1){
			// cout<<pos<<endl;
			res.PB(pos);
			pos=ans[pos].se;
		}
		// cout<<"vp "<<endl;
		// rep(i,vp.size()){
			// cout<<i<<" "<<vp[i].fi<<" "<<vp[i].se<<" "<<ans[i].fi<<endl;
		// }
		reverse(ALL(res));
		rep(i,res.size()){
			cout<<vp[res[i]].fi<<" "<<vp[res[i]].se<<endl;
		}
		cout<<0<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}
/*
8
1 1
4 4
1 1 4 1
1 1 1 4
3 1 3 4
4 3 5 3
2 4 3 5
4 1 4 4
3 3 2 2
1 4 4 4
9
1 5
5 1
5 4 5 1
1 5 1 1
1 5 5 1
2 3 2 4
5 4 1 5
3 2 2 1
4 2 4 1
1 1 5 1
5 3 4 3
11
5 5
1 0
3 1 5 1
4 3 4 2
3 1 5 5
2 3 2 2
1 0 1 2
1 2 3 4
3 4 5 5
1 0 5 2
4 0 4 1
5 5 5 1
2 3 2 4
0
*/
/*
1 1
3 1
3 4
4 4
0
-1
5 5
5 2
3 1
1 0
0
*/

Measured memory_bytes: 1348