#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
constexpr double eps = 1e-8;
#define z(x) ((abs(x)) <= eps)
struct P {
double x, y;
P (double x = 0, double y = 0) : x(x), y(y) {}
P operator + (const P &obj) const {return {x + obj.x, y + obj.y};}
P operator - (const P &obj) const {return {x - obj.x, y - obj.y};}
P operator * (const double &d) const {return {x * d, y * d};}
double operator | (const P &obj) const {return x * obj.x + y * obj.y;}
double operator ^ (const P &obj) const {return x * obj.y - y * obj.x;}
bool operator == (const P &obj) const {return z(x - obj.x) && z(y - obj.y);}
bool operator != (const P &obj) const {return ! operator == (obj);}
bool operator < (const P &obj) const {return z(x - obj.x) ? y < obj.y : x < obj.x;}
bool operator > (const P &obj) const {return obj < *this;}
int ori(const P &obj) const {double t = (*this) ^ obj; return (t > eps) - (t < -eps);}
double norm() const {return x * x + y * y;}
} zero;
P perp(const P &obj) {return {-obj.y, obj.x};}
P perpr(const P &obj) {return {obj.y, -obj.x};}
double abs(const P &obj) {return sqrt(obj.norm());}
struct argcmp {
bool operator() (const P &a, const P &b) const {
const auto quad = [](const P &a) {
if (a.y < -eps) return 1;
if (a.y > eps) return 4;
if (a.x < -eps) return 5;
if (a.x > eps) return 3;
return 2;
};
const int qa = quad(a), qb = quad(b);
if (qa != qb) return qa < qb;
return (a ^ b) > eps;
}
};
struct L {
P p, v;
L(const P &p = zero, const P &v = zero) : p(p), v(v) {}
int ori (const P &obj) const {return v.ori(obj - p);}
P inter(const L &obj) const {return p + v * ((obj.v ^ (p - obj.p)) / (v ^ obj.v));}
};
struct S {
P a, b;
int is_on(const P &p) const {
if (p == a || p == b) return -1;
return (p - a).ori(p - b) == 0 && ((p - a) | (p - b)) < -eps;
}
int is_inter(const S &s) const {
if (is_on(s.a) || is_on(s.b) || s.is_on(a) || s.is_on(b)) return -1;
const L l{a, b - a}, ls{s.a, s.b - s.a};
return l.ori(s.a) * l.ori(s.b) == -1 && ls.ori(a) * ls.ori(b) == -1;
}
};
vector<L> halfInter(vector<L> l) {
const auto check = [](const L &a, const L &b, const L &c) {
return a.ori(b.inter(c)) < 0;
};
const auto cmp = [](const L &a, const L &b) {
if (z(a.v ^ b.v) && (a.v | b.v) >= -eps) return a.ori(b.p) == -1;
return argcmp()(a.v, b.v);
};
sort(l.begin(), l.end(), cmp);
deque<L> q;
for (size_t i = 0; i < l.size(); ++i) {
if (i && l[i - 1].v.ori(l[i].v) == 0 && (l[i - 1].v | l[i].v) > eps) continue;
while (q.size() > 1 && check(l[i], q.back(), q[q.size() - 2])) q.pop_back();
while (q.size() > 1 && check(l[i], q[0], q[1])) q.pop_front();
if (!q.empty() && q.back().v.ori(l[i].v) <= 0) return vector<L>();
q.push_back(l[i]);
}
while(q.size() > 1 && check(q[0], q.back(), q[q.size() - 2])) q.pop_back();
while (q.size() > 1 && check(q.back(), q[0], q[1])) q.pop_front();
return vector<L>(q.begin(), q.end());
}
double halfInterArea(vector<L> l) {
l = halfInter(l);
if (l.size() <= 1) return 0.0;
vector<P> res;
res.resize(l.size());
for (size_t i = 0; i < l.size(); ++i)
res[i] = l[i].inter(l[i == l.size() - 1 ? 0 : i + 1]);
double area = 0;
for (size_t i = 0; i < res.size(); ++i) area += (res[i] ^ res[i == res.size() - 1 ? 0 : i + 1]);
return abs(area) / 2;
}
int tt = 0, T = 0;
inline void work() {
++tt;
double xl = rd(), yl = rd(), xr = rd(), yr = rd();
P A; A.x = rd(); A.y = rd();
P B; B.x = rd(); B.y = rd();
P C; C.x = rd(); C.y = rd();
P D; D.x = rd(); D.y = rd();
S S1(A, B), S2(C, D);
if (S1.is_inter(S2) >= 0) {printf("%.10lf\n", 0.0); return;}
P LB(xl, yl), LU(xl, yr), RB(xr, yl), RU(xr, yr);
vector<L> s;
s.eb(LB, RB - LB);
s.eb(RB, RU - RB);
s.eb(RU, LU - RU);
s.eb(LU, LB - LU);
if (A == C && B == D) {printf("%.10lf\n", (xr - xl) * (yr - yl)); return;}
if (A == D && B == C) {printf("%.10lf\n", (xr - xl) * (yr - yl)); return;}
if (A == D) swap(C, D);
if (B == C) swap(A, B);
if (B == D) {swap(A, B); swap(C, D);}
if ((B - A).ori(D - C) == 0 && (A - D).ori(B - C) == 0) {
if (A == C) {
if (((B - C) | (B - D)) < 0) { // B in middle
s.eb(B, perpr(A - B));
printf("%.10lf\n", halfInterArea(s));
} else if (((D - A) | (D - B)) < 0){
s.eb(D, perpr(C - D));
printf("%.10lf\n", halfInterArea(s));
} else printf("%.10lf\n", 0.0);
return;
} else {
if (((A - C) | (A - D)) < 0) swap(A, B);
if (((D - A) | (D - B)) < 0) swap(C, D);
s.eb(A, perpr(B - A));
s.eb(B, perpr(A - B));
s.eb(C, perpr(D - C));
s.eb(D, perpr(C - D));
printf("%.10lf\n", halfInterArea(s));
return;
}
}
if (A == C) {
s.eb(A, perp(B - A));
s.eb(A, perp(D - A));
printf("%.10lf\n", halfInterArea(s));
return;
}
puts("0.0000000000");
}
int main() {
per(t, (T = rd()), 1) work();
return 0;
}
/*
1
-347 -337 24 30
-343 25 -343 28
-343 26 -343 27
*/