/*
向量运算不会呐
抄了一个长度几百行的模板 一直过不了编译 醉了
还是抄了大佬的代码 首先把所有的线段投影到 导轨上 然后用set 分上和下分别维护一下 距离导轨最近的线段 是能够照射到的 可以证明 我们的最优答案有一端肯定是在线段的分界点上的 所以我们可以用扫描线思想
从一端扫到另一端 端点为各个分界点 这样正这反着处理两遍即可 long double 怎么输出啊 在线等挺急的
*/ #include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<set>
#define sqr(x) (x) * (x)
#define ld long double
#define ll long long
#define M 20010
using namespace std; int read() {
int nm = , f = ;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -;
for(; isdigit(c); c =getchar() ) nm = nm * + c - '';
return nm * f;
}
const ld eps = 1e-, zz = ;
ld x[M][], y[M][], len[M] ,ver[M], z[M], x0;
int p[M] , n,m; bool cmp(int a, int b) {
return (a > ? x[a][] : x[-a][]) < (b > ? x[b][]: x[-b][]);
} struct L {
int t;
bool operator <( const L &b) const {
ld w1 = (y[t][] - y[t][]) / (x[t][] - x[t][]) * (x0 - x[t][])+y[t][];
ld w2 = (y[b.t][] - y[b.t][]) / (x[b.t][] - x[b.t][]) * (x0 - x[b.t][]) + y[b.t][];
return fabs(w1) < fabs(w2);
}
};
set<L>up, down;
int main() {
int t = read();
while(t--) {
n = read();
for(int i = ; i <= n; i++) {
x[i][] = read(), y[i][] = read(), x[i][] = read(), y[i][] = read();
len[i] = sqrt(sqr(x[i][] - x[i][]) + sqr(y[i][] - y[i][]));
}
ld xn0 = read(), yn0 = read(), xn1 = read(), yn1 = read(), lenx = read();
if(xn0 > xn1) swap(xn0, xn1), swap(yn0, yn1);
ld dx = xn1 - xn0, dy = yn1 - yn0, le = sqrt(sqr(dx) + sqr(dy)),Sin = dy / le, Cos = dx / le;
for(int i = ; i <= n; i++) {
x[i][] -= xn0, x[i][] -= xn0, y[i][] -= yn0, y[i][] -= yn0;
ld a,b,c,d;
a = x[i][] * Cos + y[i][] * Sin;
b = x[i][] * Sin - y[i][] * Cos;
c = x[i][] * Cos + y[i][] * Sin;
d = x[i][] * Sin - y[i][] * Cos;
x[i][] = a, y[i][] = -b, x[i][] = c, y[i][] = -d;
}
for(int i = ; i <= n; i++) {
if(x[i][] > x[i][]) swap(x[i][], x[i][]), swap(y[i][], y[i][]);
len[i] = len[i] /(x[i][] - x[i][]);
}
m = ;
for(int i = ; i <= n; i++) p[++m] = i, p[++m] = -i;
sort(p + , p + m + , cmp);
for(int i = ; i <= m ; i++) ver[i] = ;
for(int i = , a; i <= m; i++) {
if(p[i] > ) {
a = p[i], z[i] = x0 = x[a][];
if(y[a][] > ) up.insert((L){a});
else down.insert((L){a});
}
else{
a = -p[i], z[i] = x0 = x[a][];
if(y[a][] > ) up.erase((L){a});
else down.erase((L){a});
}
if(!up.empty()) ver[i] += len[(*up.begin()).t];
if(!down.empty()) ver[i] += len[(*down.begin()).t];
}
ld ans = , sum = ; z[m + ] = 1e16;
for(int i = , l = ; i <= m; i++){
sum += (z[i] - z[i - ]) * ver[i - ];
while(z[i] - z[l + ] > lenx) l++, sum -= (z[l] - z[l - ]) * ver[l - ];
ans = max(ans, sum - max(zz, (z[i] - z[l] - lenx) * ver[l]));
}
sum = ;
for(int i = m, r = m; i >= ; i--)
{
sum += (z[i + ] - z[i]) * ver[i];
while(z[r - ] - z[i] > lenx) --r, sum -= (z[r + ] - z[r]) * ver[r];
ans = max(ans, sum - max(zz, (z[r] - z[i] - lenx) * ver[r - ]));
}
//cout << ans << "\n";
double as = ans;
printf("%.15lf\n", as);
}
return ;
}