#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define MAX_N	(200)
#define MAX_P	(MAX_N * 2)

#define T_SEG	(0)
#define T_SIGN	(1)

#define D_NONE	(0)
#define D_FWD	(1)
#define D_BWD	(2)
#define D_BOTH	(3)

#define INF	(1e10)

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef deque<int> di;

struct Pt {
  int x, y;

  Pt() {}
  Pt(int _x, int _y) { x = _x; y = _y; }

  bool operator==(Pt pt) { return x == pt.x && y == pt.y; }
  Pt operator+(Pt pt) { return Pt(x + pt.x, y + pt.y); }
  Pt operator-(Pt pt) { return Pt(x - pt.x, y - pt.y); }
  Pt operator-() { return Pt(-x, -y); }
  //Pt operator*(double t) { return Pt(x * t, y * t); }
  //Pt operator/(double t) { return Pt(x / t, y / t); }
  int dot(Pt v) { return x * v.x + y * v.y; }
  int cross(Pt v) { return x * v.y - y * v.x; }
  int dist2() { return x * x + y * y; }
  double dist() { return sqrt(dist2()); }

  string to_s() {
    stringstream ss;
    ss << "(" << x << "," << y << ")";
    return ss.str();
  }
};

struct Seg {
  Pt p0, p1;
  int i0, i1, type;

  string to_s() {
    stringstream ss;
    ss << p0.to_s() << "-" << p1.to_s();
    ss << "[" << i0 << "," << i1 << "," << type << "]";
    return ss.str();
  }
};

/* global variables */

Pt pts[MAX_P];
Seg segs[MAX_N];

vi psegs[MAX_P];
int ptypes[MAX_P];

double edges[MAX_P][MAX_P];
vi nbrs[MAX_P];

double dists[MAX_P];
int prevs[MAX_P];

/* classes */

class CompDist {
public:
  bool operator()(const int a, const int b) const {
    return (dists[b] < dists[a]);
  }
};

/* subroutines */

bool on_seg(Pt pt, Seg seg) {
  Pt v0 = seg.p0 - pt;
  Pt v1 = seg.p1 - pt;
  return ((seg.p1 - seg.p0).cross(v0) == 0 && v0.dot(v1) <= 0);
}

int pt_index(int npts, Pt *pts, Pt& pt) {
  Pt *pit = find(pts, pts + npts, pt);
  return ((pit == pts + npts) ? -1 : pit - pts);
}

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

    Pt st, gl;
    cin >> st.x >> st.y;
    cin >> gl.x >> gl.y;
    //cout << st.to_s() << gl.to_s() << endl;

    int npts = 0;
    
    for (int i = 0; i < n; i++) {
      Seg& seg = segs[i];
      cin >> seg.p0.x >> seg.p0.y >> seg.p1.x >> seg.p1.y;
      seg.type = T_SEG;
      //cout << seg.to_s() << endl;

      int pi0 = pt_index(npts, pts, seg.p0);
      if (pi0 < 0) {
	seg.i0 = npts;
	pts[npts++] = seg.p0;
      }
      else
	seg.i0 = pi0;
      
      int pi1 = pt_index(npts, pts, seg.p1);
      if (pi1 < 0) {
	seg.i1 = npts;
	pts[npts++] = seg.p1;
      }
      else
	seg.i1 = pi1;
    }
    //for (int i = 0; i < npts; i++) cout << pts[i].to_s(); cout << endl;
    //for (int i = 0; i < n; i++) cout << segs[i].to_s(); cout << endl;

    for (int i = 0; i < npts; i++) {
      psegs[i].clear();
      for (int j = 0; j < n; j++)
	if (on_seg(pts[i], segs[j])) {
	  //cout << pti.to_s() << " on " << segs[j].to_s() << endl;
	  psegs[i].push_back(j);
	}
    }
    //for (int i = 0; i < npts; i++) cout << psegs[i].size() << ' '; cout << endl;

    memset(ptypes, T_SEG, sizeof(ptypes));
    
    for (int i = 0; i < n; i++) {
      if (psegs[segs[i].i0].size() == 1 || psegs[segs[i].i1].size() == 1) {
	segs[i].type = T_SIGN;
	int i0 = segs[i].i0;
	int i1 = segs[i].i1;
	ptypes[i0] = ptypes[i1] = T_SIGN;
      }
    }
    //for (int i = 0; i < n; i++) cout << segs[i].to_s() << endl;

    for (int i = 0; i < npts; i++) {
      for (int j = 0; j < npts; j++) edges[i][j] = 0.0;
      nbrs[i].clear();
    }
    
    for (int i = 0; i < n; i++) {
      Seg& segi = segs[i];
      if (segi.type == T_SIGN) continue;

      Pt& p0 = segi.p0;
      Pt& p1 = segi.p1;
      Pt v01 = p1 - p0;

      vector<pii> spts;

      for (int j = 0; j < npts; j++) {
	vi& psj = psegs[j];
	if (find(psj.begin(), psj.end(), i) != psj.end()) {
	  pii paj((pts[j] - p0).dot(v01), j);
	  spts.push_back(paj);
	}
      }
      sort(spts.begin(), spts.end());

      //for (int j = 0; j < spts.size(); j++)
      //cout << "(" << spts[j].first << "," << spts[j].second << ")";
      //cout << endl;

      int prvj = spts[0].second;
      int direc = D_BOTH;

      for (int j = 1; j < spts.size(); j++) {
	int pj = spts[j].second;

	if (ptypes[pj] == T_SIGN) {
	  for (int k = 0; k < n; k++) {
	    Seg& segk = segs[k];
	    if (k != i && segk.type == T_SIGN &&
		(pj == segk.i0 || pj == segk.i1)) {
	      Pt vsign =
		(pj == segk.i0) ? segk.p1 - segk.p0 : segk.p0 - segk.p1;
	      int dot = vsign.dot(v01);
	      if (dot >= 0) direc &= ~D_FWD;
	      if (dot <= 0) direc &= ~D_BWD;
	    }
	  }
	}
	else {
	  double d = (pts[pj] - pts[prvj]).dist();

	  if (direc & D_FWD) {
	    edges[prvj][pj] = d;
	    nbrs[prvj].push_back(pj);
	  }
	  if (direc & D_BWD) {
	    edges[pj][prvj] = d;
	    nbrs[pj].push_back(prvj);
	  }

	  prvj = pj;
	  direc = D_BOTH;
	}
      }
    }

    for (int i = 0; i < npts; i++) {
      dists[i] = INF;
      prevs[i] = -1;
    }

    int sti = find(pts, pts + npts, st) - pts;
    int gli = find(pts, pts + npts, gl) - pts;
    
    dists[sti] = 0.0;
    vector<int> q;
    q.push_back(sti);
    CompDist compdist;
    
    while (! q.empty()) {
      sort(q.begin(), q.end(), compdist);
      int u = q.back();
      q.pop_back();

      if (u == gli) break;

      for (vi::iterator vit = nbrs[u].begin(); vit != nbrs[u].end(); vit++) {
	int v = *vit;
	double vd = dists[u] + edges[u][v];
	if (dists[v] > vd) {
	  if (dists[v] >= INF) q.push_back(v);
	  dists[v] = vd;
	  prevs[v] = u;
	}
      }
    }

    //for (int i = 0; i < npts; i++)
    //printf("dists[%d] = %lf\n", i, dists[i]);
    
    if (prevs[gli] < 0)
      cout << -1 << endl;
    else {
      di path;
      int u = gli;
      while (u >= 0) {
	path.push_front(u);
	u = prevs[u];
      }

      for (di::iterator pit = path.begin(); pit != path.end(); pit++) {
	Pt& pt = pts[*pit];
	cout << pt.x << ' ' << pt.y << endl;
      }
      cout << 0 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1904