#include <cstdio>
#include <cassert>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

const double inf = 1e10;
const double eps = 1e-8;

struct Point {
	double x, y;
	Point() : x(0), y(0) {}
	Point(const double x, const double y) : x(x), y(y) {}
	friend Point operator-(const Point &a, const Point &b) {
		return Point(a.x - b.x, a.y - b.y);
	}
	friend Point operator+(const Point &a, const Point &b) {
		return Point(a.x + b.x, a.y + b.y);
	}
	friend Point operator*(const double r, const Point &a) {
		return Point(r * a.x, r * a.y);
	}
	friend double cross(const Point &a, const Point &b) {
		return a.x * b.y - a.y * b.x;
	}
	friend double dot(const Point &a, const Point &b) {
		return a.x * b.x + a.y * b.y;
	}
};

struct Line {
	Point p, q;
	Line() : p(), q() {}
	Line(const Point p, const Point q) : p(p), q(q) {}
	double len() const {
		const double dx = p.x - q.x;
		const double dy = p.y - q.y;
		return sqrt(dx * dx + dy * dy);
	}
};

int ccw(const Point &a, const Point &b, const Point &c)
{
	const Point p = b - a;
	const Point q = c - b;
	const double cr = cross(p, q);

	if(cr > eps)
		return 1;
	if(cr < -eps)
		return -1;
	return 0;
}

bool is_touched(const Line &a, const Line &b)
{
	const int t1 = ccw(a.p, a.q, b.p);
	const int t2 = ccw(a.p, a.q, b.q);
	const int t3 = ccw(b.p, b.q, a.p);
	const int t4 = ccw(b.p, b.q, a.q);

	//printf("%d %d %d %d\n", t1, t2, t3, t4);

	if(t1 * t2 != -1)
		return false;
	if(t3 * t4 != -1)
		return false;
	return true;
}

Point compute_intersection(const Line &l1, const Line &l2)
{
	const Point v = l1.q - l1.p;
	const Point w = l2.q - l2.p;
	const Point p = l1.p;
	const Point q = l2.p;

	const double a = -v.x;
	const double b = w.x;
	const double c = -v.y;
	const double d = w.y;
	const double e = p.x - q.x;
	const double f = p.y - q.y;

	const double n = a * d - b * c;

	const double x = (e * d + f * -b) / n;
	const double y = (e * -c + f * a) / n;

	const Point r1 = p + x * v;
	const Point r2 = q + y * w;

	assert(Line(r1, r2).len() < 1e-6);

	return r1;
}

Point compute_mirror(const Line &l, const Point &p)
{
	const Point m = l.q - p;
	const Point nd = Point(l.q.y - l.p.y, -(l.q.x - l.p.x));
	const Point n = Point(nd.x / l.len(), nd.y / l.len());

	const double r = dot(m, n) * 2;
	//printf("%lf %lf %lf %lf, %lf %lf, %lf %lf %lf\n", l.p.x, l.p.y, l.q.x, l.q.y, p.x, p.y, n.x, n.y, r);

	return p + r * n;
}

double calculate_distance(const array<int, 5> &idx, const vector<Line> &ls, const Point &t, const Point &l)
{
	vector<pair<pair<int, int>, Line> > all;
	vector<Line> cur = ls;
	const int n = ls.size();

	for(int i = 0; i < n; ++i)
		all.push_back({{i, 0}, ls[i]});

	Point ttt = t;

	for(int idx_i = 0; idx_i < 5; ++idx_i) {

		const int i = idx[idx_i];
		if(i == n)
			break;
		vector<Line> next = cur;

		for(int j = 0; j < n; ++j) {

			if(i == j)
				continue;

			const Point lp = compute_mirror(cur[i], cur[j].p);
			const Point lq = compute_mirror(cur[i], cur[j].q);
			next[j] = Line(lp, lq);
			all.push_back({{j, idx_i + 1}, next[j]});
		}

		ttt = compute_mirror(cur[i], ttt);
		cur = next;
	}

	Line to = Line(l, ttt);
	//printf("%lf %lf -> %lf %lf\n", l.x, l.y, ttt.x, ttt.y);

	vector<pair<double, pair<int, int> > > cols;

	for(const auto &il : all) {

		//printf("%d: %lf %lf -> %lf %lf\n", il.first, il.second.p.x, il.second.p.y, il.second.q.x, il.second.q.y);
		if(!is_touched(il.second, to))
			continue;
		//printf("touched\n");
		const Point c = compute_intersection(il.second, to);
		const Line tooo = Line(l, c);

		//printf("%lf %d\n", tooo.len(), il.first);
		cols.push_back({tooo.len(), il.first});
	}

	sort(cols.begin(), cols.end());

	/*printf("%lf %lf -> %lf %lf\n", l.x, l.y, ttt.x, ttt.y);
	for(const auto &item : cols)
		printf("%lf %d %d\n", item.first, item.second.first, item.second.second);*/

	vector<int> ord;

	int it = 0;
	for(int i = 0; i < (int)cols.size(); ++i) {
		if(cols[i].second.second != it)
			continue;
		ord.push_back(cols[i].second.first);
		it += 1;
	}

	while(ord.size() < idx.size())
		ord.push_back(n);

	if(ord.size() != idx.size())
		return inf;
	for(int i = 0; i < (int)ord.size(); ++i) {
		if(ord[i] != idx[i])
			return inf;
	}
	return to.len();
}

int power(int x, int p)
{
	int ret = 1;
	for(int i = 0; i < p; ++i)
		ret *= x;
	return ret;
}

int main()
{
	while(true) {

		int n;
		vector<Line> ls;
		Point t, l;

		scanf("%d", &n);
		if(n == 0)
			break;
		for(int i = 0; i < n; ++i) {
			double px, py, qx, qy;
			scanf("%lf%lf%lf%lf", &px, &py, &qx, &qy);
			ls.push_back(Line(Point(px, py), Point(qx, qy)));
		}
		scanf("%lf%lf", &t.x, &t.y);
		scanf("%lf%lf", &l.x, &l.y);

		const int max_state = power(n + 1, 5);
		double ans = inf;

		for(int state = 0; state < max_state; ++state) {

			array<int, 5> idx;
			for(int i = 0; i < 5; ++i)
				idx[i] = (state / power(n + 1, i)) % (n + 1);

			bool ng = false;
			for(int i = 0; i < 4; ++i) {
				if(idx[i] == n && idx[i + 1] != n)
					ng = true;
				if(idx[i] == idx[i + 1] && idx[i] != n)
					ng = true;
			}

			if(ng)
				continue;

			const double a = calculate_distance(idx, ls, t, l);
			ans = min(a, ans);

			if(ans < a)
				continue;

			/*printf("idx:");
			for(int i = 0; i < 5 && idx[i] != n; ++i)
				printf("%d ", idx[i]);
			printf("\n%lf\n\n", a);*/
		}

		printf("%.20lf\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1100