#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<queue>

using namespace std;

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

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

typedef long double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> Pol;

const D INF = 1e40;
const D EPS = 1e-8;
const D PI = acos(-1);

int sig(D r) {return (r < -EPS) ? -1 : (r > EPS) ? 1 : 0;}
bool eq(D a, D b) {return abs(a - b) < EPS;}
bool near(P a, P b) {return abs(a - b) < EPS;}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.second - a.first;}

// 線分abに対する点xの位置
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(L s, P p) {
  P a = vec(s);
  p -= s.first;
  D cr = det(a, p);
  if (eq(cr, 0)) {
    if (sig(dot(a, p)) < 0) return BACK;
    if (sig(norm(a) - norm(p)) < 0) return FRONT;
    return ON;
  }
  return (cr > 0) ? LEFT : RIGHT;
}

// 角度
D ang(P p) {D theta = arg(p); return sig(theta - PI) < 0 ? theta : -PI;}
// 有向角度
D ang(P base, P a, P b) {return ang((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.first + proj(vec(l), p - l.first);}
P refl(L l, P p) {return perp(l, p) * (D)2 - p;}

// 交差判定
bool iLL(L a, L b) {return !eq(det(vec(a), vec(b)), 0);}
bool eqL(L a, L b) {return !iLL(a, b) && eq(det(vec(a), b.first - a.first), 0);}
bool iLS(L a, L b) {return sig(det(vec(a), b.first - a.first)) * sig(det(vec(a), b.second - a.first)) <= 0;}
bool iLSs(L a, L b) {return sig(det(vec(a), b.first - a.first)) * sig(det(vec(a), b.second - a.first)) < 0;}
bool iSS(L a, L b) {
  int cwa = ccw(a, b.first) | ccw(a, b.second);
  int cwb = ccw(b, a.first) | ccw(b, a.second);
  return ((cwa | cwb) & ON) || ((cwa & cwb) == (LEFT | RIGHT));
}
bool iSSs(L a, L b) {return ((ccw(a, b.first) | ccw(a, b.second)) & (ccw(b, a.first) | ccw(b, a.second))) == (LEFT | RIGHT);}

// 交点
P pLL(L a, L b) {return a.first + vec(a) * (det(vec(b), b.first - a.first) / det(vec(b), vec(a)));}

// 距離
D dLP(L l, P x) {return abs(det(vec(l), x - l.first)) / abs(vec(l));}
D dSP(L s, P x) {
  if (sig(dot(vec(s), x - s.first)) <= 0) return abs(x - s.first);
  if (sig(dot(-vec(s), x - s.second)) <= 0) return abs(x - s.second);
  return dLP(s, x);
}
D dLL(L a, L b) {return iLL(a, b) ? 0 : dLP(a, b.first);}
D dLS(L a, L b) {return iLS(a, b) ? 0 : min(dLP(a, b.first), dLP(a, b.second));}
D dSS(L a, L b) {return iSS(a, b) ? 0 : min(min(dSP(a, b.first), dSP(a, b.second)), min(dSP(b, a.first), dSP(b, a.second)));}

// 比較関数
namespace std {
  bool operator<(P a, P b) {return eq(a.X, b.X) ? a.Y < b.Y : a.X < b.X;}
}
L sortBase;
bool lessArg(P a, P b) {
  D ang1 = ang(sortBase.first, sortBase.second, a);
  D ang2 = ang(sortBase.first, sortBase.second, b);
  return eq(ang1, ang2) ? norm(a) > norm(b) : ang1 < ang2;
}

// 円
struct C{
  P c; D r;
  C() {}
  C(P c, D r) : c(c), r(r) {}
};

// 2円の位置関係
enum RELATION{SAME = 1, CONTAIN = 2, OVER = 4, NO_CROSS = 8, ONE_CROSS = 16, ONE_CONTAIN_CROSS = 32, ONE_OVER_CROSS = 64, TWO_CROSS = 128};
int cRel(C c1, C c2) {
  D d = abs(c1.c - c2.c);
  if (near(c1.c, c2.c) && eq(c1.r, c2.r)) return SAME;
  if (sig(d - (c1.r - c2.r)) < 0) return OVER;
  if (sig(d - (c2.r - c1.r)) < 0) return CONTAIN;
  if (eq(d, c1.r - c2.r)) return ONE_OVER_CROSS;
  if (eq(d, c2.r - c1.r)) return ONE_CONTAIN_CROSS;
  if (eq(d, c1.r + c2.r)) return ONE_CROSS;
  if (sig(d - (c1.r + c2.r)) > 0) return NO_CROSS;
  return TWO_CROSS;
}

// 点が円に含まれるか
bool iCP(C c, P p) {return sig(abs(p - c.c) - c.r) <= 0;}
// 交差判定
bool iCL(C c, L l) {return sig(c.r - dLP(l, c.c)) >= 0;}
// 円と交差せず完全に含まれても良い場合は&&以降を削除
bool iCS(C c, L s) {return iCL(c, s) && sig(c.r - max(abs(s.first - c.c), abs(s.second - c.c))) <= 0;}
bool iCC(C a, C b) {return sig(abs(a.c - b.c) - abs(a.r - b.r) >= 0) && sig(abs(a.c - b.c) - a.r - b.r) <= 0;}

// 交点
pair<P, P> pCC(C a, C b) {
  D x = (norm(a.c - b.c) + a.r * a.r - b.r * b.r) / (2 * abs(a.c - b.c));
  P e = (b.c - a.c) / abs(b.c - a.c);
  P y = e * P(0, sqrt(max(a.r * a.r - x * x, (D)0)));
  return make_pair(a.c + e * x - y, a.c + e * x + y);
}
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sqrt(max(c.r * c.r - norm(x - c.c), (D)0));
  return make_pair(x - y, x + y);
}

// 角の内外判定 角abの内部にあれば正、辺上は0、外部は負
int sAP(P a, P b, P c) {return sig(det(a, c)) - sig(det(b, c)) - sig(det(a, b));}

// 多角形の面積
D aPol(Pol vp) {
  D ret = 0;
  rep (i, vp.size()) ret += det(vp[i], vp[(i + 1) % vp.size()]);
  return abs(ret / 2);
}

// 三角形の面積
D aTri(D a, D b, D c){
  D s = (a + b + c) / 2;
  return sqrt(max(s * (s - a) * (s - b) * (s - c), (D)0));
}

// 多角形の内外判定 内部:1、周上:0、外部:-1
int sGP(Pol pol, P p) {
  int side = -1;
  rep (i, pol.size()) {
    P p0 = pol[i] - p, p1 = pol[(i + 1) % pol.size()] - p;
    if (sig(det(p0, p1)) == 0 && sig(dot(p0, p1)) <= 0) return 0;
    if (p0.Y > p1.Y) swap(p0, p1);
    if (sig(p0.Y) <= 0 && 0 < sig(p1.Y) && sig(det(p0, p1)) > 0) side *= -1;
  }
  return side;
}

// 凸包
Pol convexHull(Pol p) {
  int m = 0;
  vector<P> q(p.size() * 2);
  sort(p.begin(), p.end());
  for (int i = 0; i < int(p.size()); q[m++] = p[i++]) for (; m > 1 && sig(det(q[m - 1] - q[m - 2], p[i] - q[m - 2])) <= 0; --m);
  for (int i = p.size() - 2, r = m; i >= 0; q[m++] = p[i--]) for (; m > r && sig(det(q[m - 1] - q[m - 2], p[i] - q[m - 2])) <= 0; --m);
  q.resize(m - 1);
  return q;
}

// 凸包カット
Pol convexCut(Pol p, L l) {
  vector<P> q;
  rep (i, p.size()) {
    if (ccw(l, p[i]) & (LEFT | BACK | ON | FRONT)) q.push_back(p[i]);
    if (iLSs(l, L(p[i], p[(i + 1) % p.size()]))) q.push_back(pLL(l, L(p[i], p[(i + 1) % p.size()])));
  }
  return q;
}

// 線分をマージする
vector<L> merge(vector<L> s) {
  rep (i, s.size()) if (s[i].second < s[i].first) swap(s[i].first, s[i].second);
  sort(s.begin(), s.end());
  rep (i, s.size()) rep (j, i) if (iSS(s[i], s[j]) && !iLL(s[i], s[j])) {
    s[j].second = max(s[i].second, s[j].second);
    s.erase(s.begin() + i--);
    break;
  }
  return s;
}

// 線分アレンジメント 隣の点への辺のみを持つ
pair<vector<P>, vector<vector<int> > > sArr(vector<L> s) {
  //s = merge(s);
  vector<P> vp;
  rep (i, s.size()) {
    vp.push_back(s[i].first);
    vp.push_back(s[i].second);
  }
  //rep (i, s.size()) rep (j, i) if (iSS(s[i], s[j])) vp.push_back(pLL(s[i], s[j]));
  sort(vp.begin(), vp.end());
  vp.erase(unique(vp.begin(), vp.end(), near), vp.end());
  vector<vector<int> > g(vp.size());
  rep (i, s.size()) {
    vector<pair<D, int> > v;
    rep (j, vp.size()) if (ccw(s[i], vp[j]) == ON) v.push_back(make_pair(norm(vp[j] - s[i].first), j));
    sort(v.begin(), v.end());
    rep (j, v.size() - 1) {
      g[v[j + 1].second].push_back(v[j].second);
      g[v[j].second].push_back(v[j + 1].second);
    }
  }
  return make_pair(vp, g);
}

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) break;
    P s, g;
    cin >> s.X >> s.Y >> g.X >> g.Y;
    vector<L> vl(n);
    rep (i, n) cin >> vl[i].first.X >> vl[i].first.Y >> vl[i].second.X >> vl[i].second.Y;
    pair<vector<P>, vector<vector<int> > > sarr = sArr(vl);
    vector<P> vp = sarr.first;
    vector<vector<int> > edge = sarr.second;
    priority_queue<pair<D, vector<int> >, vector<pair<D, vector<int> > >, greater<pair<D, vector<int> > > > que;
    int si = -1, gi = -1;
    rep (i, vp.size()) {
      if (near(vp[i], s)) si = i;
      if (near(vp[i], g)) gi = i;
    }
    pair<D, vector<int> > dis[222][222];
    rep (i, 222) rep (j, 222) dis[i][j].first = INF;
    rep (i, edge[si].size()) {
      vector<int> vi;
      vi.push_back(si);
      vi.push_back(edge[si][i]);
      que.push(make_pair(abs(vp[si] - vp[edge[si][i]]), vi));
    }
    while (!que.empty()) {
      pair<D, vector<int> > now = que.top();
      que.pop();
      int nn = now.second[now.second.size() - 1];
      int pp = now.second[now.second.size() - 2];
      if (dis[nn][pp].first <= now.first) continue;
      dis[nn][pp] = now;
      rep (i, edge[nn].size()) {
	if (pp == edge[nn][i]) continue;
	if (ccw(L(vp[pp], vp[nn]), vp[edge[nn][i]]) == FRONT) {
	  bool ok = true;
	  rep (j, edge[nn].size()) {
	    if (edge[edge[nn][j]].size() > 1u) continue;
	    if (sig(abs(ang(vp[nn], vp[pp], vp[edge[nn][j]])) - PI / 2) >= 0) {
	      ok = false;
	      break;
	    }
	  }
	  if (!ok) continue;
	}
	vector<int> vi = now.second;
	vi.push_back(edge[nn][i]);
	que.push(make_pair(now.first + abs(vp[nn] - vp[edge[nn][i]]), vi));
      }
    }
    D mn = INF;
    int res = -1;
    rep (i, vp.size()) {
      if (mn > dis[gi][i].first) {
	mn = dis[gi][i].first;
	res = i;
      }
    }
    if (res == -1) cout << -1 << endl;
    else {
      vector<P> vvp;
      rep (i, vl.size()) {
	int flag = 0;
	rep (j, vl.size()) if (i != j) {
	  if (ccw(vl[j], vl[i].first) == ON) flag |= 1;
	  if (ccw(vl[j], vl[i].second) == ON) flag |= 2;
	}
	if (flag == 3) {
	  vvp.push_back(vl[i].first);
	  vvp.push_back(vl[i].second);
	}
      }
      rep (i, dis[gi][res].second.size()) {
	int ii = dis[gi][res].second[i];
	rep (j, vvp.size()) if (near(vvp[j], vp[ii])) {
	  cout << int(vp[ii].X + 0.5) << " " << int(vp[ii].Y + 0.5) << endl;
	  break;
	}
      }
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3792