Problem: A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflections. Your job is to find the shortest beam path from the generator to the target and answer the length of the path.

Figure G-1 shows examples of possible beam paths, where the bold line represents the shortest one.

<image>

Figure G-1: Examples of possible paths

Input

The input consists of a number of datasets. The end of the input is indicated by a line containing a zero.

Each dataset is formatted as follows. Each value in the dataset except n is an integer no less than 0 and no more than 100.

> n
>  PX1 PY1 QX1 QY1
>  ...
>  PXn PYn QXn QYn
>  TX TY
>  LX LY
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 5), representing the number of mirrors. The following n lines list the arrangement of mirrors on the plane. The coordinates (PXi, PYi) and (QXi, QYi) represent the positions of both ends of the mirror. Mirrors are apart from each other. The last two lines represent the target position (TX, TY) and the position of the beam generator (LX, LY). The positions of the target and the generator are apart from each other, and these positions are also apart from mirrors.

The sizes of the target object and the beam generator are small enough to be ignored. You can also ignore the thicknesses of mirrors.

In addition, you can assume the following conditions on the given datasets.

* There is at least one possible path from the beam generator to the target.
* The number of reflections along the shortest path is less than 6.
* The shortest path does not cross or touch a plane containing a mirror surface at any points within 0.001 unit distance from either end of the mirror.
* Even if the beam could arbitrarily select reflection or passage when it reaches each plane containing a mirror surface at a point within 0.001 unit distance from one of the mirror ends, any paths from the generator to the target would not be shorter than the shortest path.
* When the beam is shot from the generator in an arbitrary direction and it reflects on a mirror or passes the mirror within 0.001 unit distance from the mirror, the angle θ formed by the beam and the mirror satisfies sin(θ) > 0.1, until the beam reaches the 6th reflection point (exclusive).



Figure G-1 corresponds to the first dataset of the Sample Input below. Figure G-2 shows the shortest paths for the subsequent datasets of the Sample Input.

<image>

Figure G-2: Examples of the shortest paths

Output

For each dataset, output a single line containing the length of the shortest path from the beam generator to the target. The value should not have an error greater than 0.001. No extra characters should appear in the output.

Sample Input


2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0


Output for the Sample Input


180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809






Example

Input

2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0


Output

180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809

Solution (in CPP):

Solution:
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <csetjmp>
#include <cassert>
#include <cstdio>
using namespace std;

#define REP(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)
 

const double EPS = 1e-9;

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

typedef complex<double> point;

namespace std {
	bool operator==(const point &p, const point &q) {
		return abs(p.X - q.X) < EPS && abs(p.Y - q.Y) < EPS;
	}

	bool operator!=(const point &p, const point &q) {
		return !(p == q);
	}

	bool operator<(const point &p, const point &q) {
		return p.X + EPS < q.X || (abs(p.X - q.X) < EPS && p.Y + EPS < q.Y);
	}

	bool operator>(const point &p, const point &q) {
		return q < p;
	}
}

double dot(const point &l, const point &r) {
	return real(conj(l)*r);
}

double cross(const point &l, const point &r) {
	return imag(conj(l)*r);
}

struct line {
	point a, b;
	line(const point& a, const point& b):a(a), b(b){}
};

struct segment {
	point a, b;
	segment(const point& a, const point& b):a(a), b(b){}
};

typedef vector<point> polygon;

inline int ccw(const point& a, point b, point c) {
	b = b - a;
	c = c - a;
	const double tmp = cross(b, c);
	if(tmp > EPS) return 1; // ccw
	if(tmp < -EPS) return -1; // cw
	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 順で一直線上
}

inline point projection(const line& l, const point& p) {
	const point dif = l.b - l.a;
	const double tmp = dot(p - l.a, dif) / norm(dif);
	return l.a + dif * tmp;
}

inline bool intersect(const segment& s, const segment& t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
		ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

inline bool intersect(const segment& s, const point& p) {
	return ccw(s.a, s.b, p) == 0;
}

inline double dist(const point& a, const point& b) {
	return abs(a - b);
}

inline point crosspoint(const segment& s, const segment& t) {
	if(!intersect(s, t)) // 交点を持たない
		return s.a; // 用改善

	const double tmp = cross(s.b - s.a, t.b - t.a);
	if(abs(tmp) < EPS) { // 一直線上
		if(intersect(s, t.a)) return t.a;
		if(intersect(s, t.b)) return t.b;
		if(intersect(t, s.a)) return s.a;
		return s.b;
	}

	return t.a + (t.b - t.a) * cross(s.b - s.a, s.b - t.a) * (1.0 / tmp);
}

point reflection(const line &l, point pt)
{
	return pt + (projection(l, pt) - pt) * 2.0;
}

point reflection(const segment &s, point pt)
{
	return reflection(line(s.a, s.b), pt);
}

int n;

vector<segment> mirrors;
point target, laser;

double ans;
const double INF = 1e100;

double solve(vector<int> &idx)
{
	vector<segment> ms;
	point las, tar;
	vector<point> path;
	double d;

	rep(i, idx.size())
		ms.push_back(mirrors[idx[i]]);

	las = laser;
	rep(i, ms.size())
		las = reflection(ms[i], las);

	tar = target;
	d = dist(las, tar); 
	path.push_back(tar);
	for (int i = ms.size()-1; i >= 0; i--) {
		segment s = segment(las, tar);
		if (!intersect(s, ms[i]))
			return INF;
		las = reflection(ms[i], las);
		tar = crosspoint(s, ms[i]);
		path.push_back(tar);
	}
	path.push_back(las);

	REP(i, 1, path.size()) {
		segment s = segment(path[i-1], path[i]);
		rep(j, mirrors.size()) {
			if (!intersect(mirrors[j], s.a)
				&& !intersect(mirrors[j], s.b)
				&& intersect(mirrors[j], s))
				return INF;
		}
	}

	return d;
}

void dfs(vector<int> &idx)
{
	int sz = idx.size();
	if (sz > 5) return;

	ans = min(ans, solve(idx));
	rep(i, n) {
		if (sz > 0 && i == idx[sz-1]) continue;
		idx.push_back(i);
		dfs(idx);
		idx.pop_back();
	}
}

int main()
{
	while (cin >> n, n) {
		mirrors = vector<segment>();
		rep(i, n) {
			int px, py, qx, qy;
			cin >> px >> py >> qx >> qy;
			mirrors.push_back(segment(point(px, py), point(qx, qy)));
		}
		
		{
			int tx, ty;
			int lx, ly;
			cin >> tx >> ty;
			target = point(tx, ty);
			cin >> lx >> ly;
			laser = point(lx, ly);
		}

		ans = INF;
		vector<int> idx;
		dfs(idx);
		printf("%.20lf\n", ans);
	}
	return 0;
}