#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

#include <complex>
#include <vector>

typedef complex<double> Point;
typedef vector<Point> Polygon;

//static const double EPS = 1e-8;
static const double INF = 1e+10;

#define CURR(P, i) (P[i])
#define NEXT(P, i) (P[(i + 1) % P.size()])

struct Line : public vector<Point> {
  Line() {;}
  Line(Point a, Point b) { push_back(a); push_back(b); }
};

namespace std {
  bool operator<(const Point &lhs, const Point &rhs) {
    return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
  }
}

inline double cross(const Point &a, const Point &b) {
  return imag(conj(a) * b);
}

inline double dot(const Point &a, const Point &b) {
  return real(conj(a) * b);
}

inline int ccw(Point a, Point b, Point c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0) { return 1; }
  if (cross(b, c) < 0) { return -1; }
  if (dot(b, c) < 0) { return 2; }
  if (norm(b) < norm(c)) { return -2; }
  return 0;
}


bool intersectSS(const Line &s, const Line &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
    ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

bool intersectSP(const Line &s, const Point &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS;
}
Point projection(const Line &l, const Point &p) {
  double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
  return l[0] + t * (l[0] - l[1]);
}

Point reflection(const Line &l, const Point &p) {
  return p + 2.0 * (projection(l, p) - p);
}

double distanceSP(const Line &s, const Point &p) {
  const Point r = projection(s, p);
  if (intersectSP(s, r)) { return abs(r - p); }
  return min(abs(s[0] - p), abs(s[1] - p));
}

Point crosspointSS(const Line &l, const Line &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) {
    assert(false);
    if (intersectSP(l, m[0])) { return m[0]; }
    if (intersectSP(l, m[1])) { return m[1]; }
    if (intersectSP(m, l[0])) { return l[0]; }
    if (intersectSP(m, l[1])) { return l[1]; }
    return m[0];
  }
  if (abs(A) < EPS) { assert(false); }
  return m[0] + B / A * (m[1] - m[0]);
}


int n;
Line mirror[10];
Point origin;

double Calc(const vector<int> &seq, Point target) {
  double ret = 0.0;
  Point from = origin;
  int prev = -1;
  for (int i = seq.size() - 1; i >= 0; i--) {
    double minDist = 1e+100;
    int index = -1;
    Line vect = Line(from, target);
    REP(j, n) {
      if (j == prev) { continue; }
      if (intersectSS(vect, mirror[j])) {
        double d = abs(from - crosspointSS(vect, mirror[j]));
        if (d < minDist) {
          minDist = d;
          index = j;
        }
      }
    }
    if (index != seq[i]) { return 1e+100; }
    Point to = crosspointSS(vect, mirror[index]);
    target = reflection(mirror[index], target);
    ret += abs(from - to);
    from = to;
    prev = index;
  }
  Line vect = Line(from, target);
  REP(i, n) {
    if (i == prev) { continue; }
    if (intersectSS(vect, mirror[i])) { return 1e+100; }
  }
  ret += abs(from - target);
  return ret;
}

double Init(vector<int> seq, int from, Point target) {
  double ret = 1e+100;
  ret = min(ret, Calc(seq, target));
  if (seq.size() == 5) { return ret; }
  REP(i, n) {
    if (i == from) { continue; }
    seq.push_back(i);
    Point ntarget = reflection(mirror[i], target);
    ret = min(ret, Init(seq, i, ntarget));
    seq.pop_back();
  }
  return ret;
}

int main() {
  while (scanf("%d ", &n), n) {
    REP(i, n) {
      int fx, fy, tx, ty;
      scanf("%d %d %d %d", &fx, &fy, &tx, &ty);
      mirror[i] = Line(Point(fx, fy), Point(tx, ty));
    }
    int fx, fy, tx, ty;
    scanf("%d %d %d %d", &fx, &fy, &tx, &ty);
    origin = Point(fx, fy);
    Point target = Point(tx, ty);
    double ans = Init(vector<int>(), -1, target);
    printf("%.8f\n", ans);
  }
}

Measured memory_bytes: 972