#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

#define x first
#define y second
#define fi first
#define se second
#define mkp make_pair

typedef pair<int,int> pii;

const int INF = 1e9;

int n;
pii s, g;
vector<pair<pii,pii> > lineseg, street, sign;

template<class T>
T sqr(T x) {
	return x * x;
}

double sqrdist(pii a, pii b) {
	return sqr(a.x-b.x) + sqr(a.y-b.y);
}

double dist(pii a, pii b) {
	return sqrt(sqr(a.x-b.x) + sqr(a.y-b.y));
}

int main() {
	while(cin >> n, n) {
		cin >> s.x >> s.y;
		cin >> g.x >> g.y;
		lineseg.clear();
		street.clear();
		sign.clear();
		for(int i = 0; i < n; i++) {
			pii a, b;
			cin >> a.x >> a.y >> b.x >> b.y;
			lineseg.push_back(mkp(a,b));
		}

		// street or sign.
		for(int i = 0; i < lineseg.size(); i++) {
			bool a, b;
			pair<pii,pii> c;
			a = b = true;
			c = lineseg[i];
			for(int j = 0; j < lineseg.size(); j++) {
				if(j != i) {
					pair<pii,pii> d;
					d = lineseg[j];
					if(fabs(dist(d.fi, c.fi) + dist(d.se, c.fi) - dist(d.fi, d.se)) < 1e-9)
						a = false;
					if(fabs(dist(d.fi, c.se) + dist(d.se, c.se) - dist(d.fi, d.se)) < 1e-9)
						b = false;
				}
			}
			if(a || b) {
				if(a)
					swap(c.fi, c.se);
				sign.push_back(c);
			}
			else
				street.push_back(c);
		}

		// make graph.
		// vertex
		map<pii, int> vertex;
		for(int i = 0; i < street.size(); i++) {
			if(vertex.find(street[i].fi) == vertex.end()) {
				vertex.insert(mkp(street[i].fi, vertex.size()));
			}
			if(vertex.find(street[i].se) == vertex.end()) {
				vertex.insert(mkp(street[i].se, vertex.size()));
			}
		}

		// edge
		double edge[512][512];
		double wf[512][512];
		for(int i = 0; i < 512; i++) {
			for(int j = 0; j < 512; j++) {
				edge[i][j] = INF;
				wf[i][j] = INF;
			}
			edge[i][i] = 0;
			wf[i][i] = 0;
		}
		
		vector<pair<pii,pii> > cut(street.begin(), street.end());
		for(int i = 0; i < cut.size(); i++) {
			pair<pii,pii> a, b;
			a = cut[i];
			for(int j = 0; j < cut.size(); j++) {
				b = cut[j];
				if((fabs(dist(a.fi, b.fi) + dist(a.se, b.fi) - dist(a.fi, a.se)) < 1e-9 && a.fi != b.fi && a.se != b.fi)){
					cut.erase(cut.begin()+i);
					cut.push_back(mkp(a.fi,b.fi));
					cut.push_back(mkp(b.fi,a.se));
					i--;
					break;
				}
				else if(fabs(dist(a.fi, b.se) + dist(a.se, b.se) - dist(a.fi, a.se)) < 1e-9 && a.fi != b.se && a.se != b.se) {
					cut.erase(cut.begin()+i);
					cut.push_back(mkp(a.fi,b.se));
					cut.push_back(mkp(b.se,a.se));
					i--;
					break;
				}
			}
		}

		for(int i = 0; i < cut.size(); i++) {
			pair<pii,pii> a, b;
			a = cut[i];
			bool f2s, s2f;
			f2s = s2f = true;
			for(int j = 0; j < sign.size(); j++) {
				b = sign[j];
				if(fabs(dist(a.fi, b.fi) + dist(a.se, b.fi) - dist(a.fi, a.se)) < 1e-9) {
					if(fabs(sqrdist(a.fi, b.fi) + sqrdist(b.fi, b.se) - sqrdist(a.fi, b.se)) < 1e-9) {
						f2s = s2f = false;
					}
					else if(sqrdist(a.fi, b.fi) + sqrdist(b.fi, b.se) - sqrdist(a.fi, b.se) > 0) {
						s2f = false;
					}
					else {
						f2s = false;
					}
				}
			}
			if(f2s) {
				edge[vertex[a.fi]][vertex[a.se]] = wf[vertex[a.fi]][vertex[a.se]] = dist(a.fi, a.se);
			}
			if(s2f) {
				edge[vertex[a.se]][vertex[a.fi]] = wf[vertex[a.se]][vertex[a.fi]] = dist(a.fi, a.se);
			}
		}

		// warshall floyd
		for(int i = 0; i < vertex.size(); i++) {
			for(int j = 0; j < vertex.size(); j++) {
				for(int k = 0; k < vertex.size(); k++) {
					wf[j][k] = min(wf[j][k], wf[j][i] + wf[i][k]);
				}
			}
		}

		double min_cost;
		min_cost = wf[vertex[s]][vertex[g]];

		if(fabs(min_cost - INF) < 1e-9)
			cout << -1 << endl;
		else {
			vector<int> path;
			int indx, indx_s;
			indx = vertex[g];
			indx_s = vertex[s];
			while(indx != indx_s) {
				int nex = -1;
				path.push_back(indx);
				for(int i = 0; i < vertex.size(); i++) {
					if(i != indx && fabs(wf[indx_s][i] + edge[i][indx] - wf[indx_s][indx]) < 1e-9)
						nex = i;
				}
				indx = nex;
			}
			path.push_back(indx_s);
			reverse(path.begin(), path.end());

			vector<pii> indx2pt;
			indx2pt.resize(vertex.size());
			for(map<pii,int>::iterator iter = vertex.begin(); iter != vertex.end(); iter++) {
				indx2pt[iter->se] = iter->fi;
			}

			for(int i = 0; i < path.size(); i++) {
				pii tmp = indx2pt[path[i]];
				cout << tmp.x << " " << tmp.se << endl;
			}
			cout << 0 << endl;
		}
	}
}

Measured memory_bytes: 5344