// AOJ 1171: Laser Beam Reflections
// 2017.12.19 bal4u@uu

#include <stdio.h>
#include <math.h>

#define EPS 1e-8
#define ZERO(a)   (fabs(a)<=EPS)
#define EQ(a,b)   (fabs((a)-(b))<=EPS)

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG;
typedef struct { PP p; int mid; } T;

T tbl[7];
SEG mir[7]; int n;
PP start, goal;
double ans;

int pOnSeg(PP *p, SEG *u)
{
	double x1, y1, x2, y2, d;
	double a, b;

	x1 = u->s.x, y1 = u->s.y, x2 = u->e.x, y2 = u->e.y;
	if (!EQ(x1, x2) && x1 >= x2) {
		d = x1, x1 = x2, x2 = d;
		d = y1, y1 = y2, y2 = d;
	}
	a = (p->y - y1)*(x2 - x1);
	b = (y2 - y1)*(p->x - x1);
	return (EQ(x1, p->x) || x1 <= p->x) && 
		   (EQ(p->x, x2) || p->x <= x2) &&
	       (((EQ(y1, y2)   || y1 <= y2) &&
		     (EQ(y1, p->y) || y1 <= p->y) &&
		     (EQ(p->y, y2) || p->y <= y2)) ||
		   ((!EQ(y1,y2) && y1 >= y2) &&
		     (EQ(y2, p->y) || y2 <= p->y) &&
		    (EQ(p->y, y1)  || p->y <= y1)))
		  && EQ(a, b);
}

int pOnLine(PP *p, SEG *u)
{
	double a = (p->x - u->s.x)*(u->e.y - u->s.y);
	double b = (p->y - u->s.y)*(u->e.x - u->s.x);
	return EQ(a,b);
}

int intersection(PP *ans, PP *p1, PP *p2, SEG *u)
{
	double t1, t2, t3, t4;
	double bo, ua;
	double a, b;
	SEG v;
	int f1, f2, f3, f4;

	if (pOnLine(p1, u) || pOnLine(p2, u)) return 0;
	a = (p2->y - p1->y)*(u->s.x - u->e.x);
	b = (u->s.y - u->e.y)*(p2->x - p1->x);
	if (EQ(a, b)) return 0;

	t1 = (p1->y - u->s.y)*(u->s.x - u->e.x) - (p1->x - u->s.x)*(u->s.y - u->e.y);
	t2 = (p2->y - u->s.y)*(u->s.x - u->e.x) - (p2->x - u->s.x)*(u->s.y - u->e.y);
	t3 = (u->s.y - p1->y)*(p1->x - p2->x) - (u->s.x - p1->x)*(p1->y - p2->y);
	t4 = (u->e.y - p1->y)*(p1->x - p2->x) - (u->e.x - p1->x)*(p1->y - p2->y);
	t1 *= t2, t3 *= t4;

	if (!ZERO(t1) && !ZERO(t3) && t1 <= 0 && t3 <= 0) {
		bo = (u->e.y - u->s.y)*(p2->x - p1->x) - (u->e.x - u->s.x)*(p2->y - p1->y);
		ua = (u->e.x - u->s.x)*(p1->y - u->s.y) - (u->e.y - u->s.y)*(p1->x - u->s.x);
		ans->x = p1->x + ua/bo * (p2->x - p1->x);
		ans->y = p1->y + ua/bo * (p2->y - p1->y);
		return 1;
	}

	f1 = pOnSeg(p1, u), f2 = pOnSeg(p2, u);
	v.s = *p1, v.e = *p2;
	f3 = pOnSeg(&(u->s), &v), f4 = pOnSeg(&(u->e), &v);
	return f1 || f2 || f3 || f4;
}

double dist(PP *p1, PP *p2)
{
	return hypot(p1->x - p2->x, p1->y - p2->y);
}

void mirrorPoint(PP *ans, PP *p, SEG *u)  // segment a--b
{
	double A, B, C;   // Ax + By + C = 0 

	A = u->s.y - u->e.y, B = u->e.x - u->s.x, C = u->e.y*u->s.x - u->e.x*u->s.y;
	ans->x = p->x - 2 * A * (A * p->x + B * p->y + C) / (A*A + B*B);
	ans->y = p->y - 2 * B * (A * p->x + B * p->y + C) / (A*A + B*B);
}

int check(PP *fr, int k)
{
	int i, j;
	PP a, b, t;

	a.x = fr->x, a.y = fr->y;
	for (i = k-1; i > 0; i--) {
		if (!intersection(&b, &tbl[i].p, &a, mir + tbl[i].mid)) return 0;
		for (j = 0; j < n; j++) if (intersection(&t, &a, &b, mir + j)) return 0;
		a = b;
	}
	for (j = 0; j < n; j++) if (intersection(&t, &a, &start, mir + j)) return 0;
	return 1;
}

void rec(int k, int idx)
{
	int i, cnt, who;
	PP a;
	double d;

	if (k > 5) return;
	if (pOnLine(&tbl[k-1].p, mir+idx)) return;

	mirrorPoint(&tbl[k].p, &tbl[k-1].p, mir+idx), tbl[k].mid = idx;

	cnt = 0, who = -1;
	for (i = 0; i < n; i++)	{
		if (intersection(&a, &tbl[k].p, &goal, mir+i)) cnt++, who = i;
	}

	if (cnt == 1 && who == idx) {
		d = dist(&tbl[k].p, &goal);
		if (d >= ans) return;
		if (check(&a, k)) {	ans = d; return; }
	}
	for (i = 0; i < n; i++) if (i != idx) rec(k+1, i);
}

int main()
{
	int i;
	PP a;

	while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++)
			scanf("%lf%lf%lf%lf", &mir[i].s.x, &mir[i].s.y, &mir[i].e.x, &mir[i].e.y);

		scanf("%lf%lf%lf%lf", &goal.x, &goal.y, &start.x, &start.y);

		for (i = 0; i < n; i++)	{
			if (intersection(&a, &start, &goal, mir+i)) break;
		}
		if (i >= n) { printf("%.10lf\n", dist(&start, &goal)); continue; }

		ans = 1e8; tbl[0].p = start;
		for (i = 0; i < n; i++) rec(1, i);
		printf("%.10lf\n", ans);
	}
	return 0;
}