#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define For(i,n) for( int i=0; i < n; i++) #define FOR(i,a,b) for( __typeof(b) i=(a); i<=(b); i++) #define ALL(c) c.begin() , c.end() #define LL long long #define int64 LL #define Set(t,v) memset((t), (v), sizeof(t)) typedef vector < int > VI; typedef pair< int , int > PII; #define fr first #define se second #define pi M_PI #define rad(x) (x)*acos(-1)/180.0 stringstream ss; /**************************Code****************************/ const double EPS = 1e-8; const double INF = 1e12; typedef complex point; //point typedef vector < point > polygon; namespace std { bool operator < (const point& a, const point& b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } double cross (const point& a, const point& b) { return imag (conj(a) *b); } double dot (const point& a, const point& b) { return real (conj(a) *b); } struct L: public vector { //line L (const point &a, const point &b) { push_back(a); push_back(b); } }; typedef vector G; typedef vector polygon; struct C { // circle point p; double r; C (const point &p, double r) : p(p), r(r) {} }; int ccw (point a, point b, point c) { b -= a; c -= a; if (cross (b, c) > 0) return +1; // counter clockwise if (cross (b, c) < 0) return -1; // clockwise if (dot (b, c) < 0) return +2; // c--a--b ON line if (norm (b) < norm (c)) return -2; // a--b--c ON line return 0; } double cross(double ax, double ay, double bx, double by) { return ax*by - bx*ay; } double dot(double ax, double ay, double bx, double by) { return ax * bx + ay * by; } double ang(double ax, double ay, double bx, double by) { return atan2(cross(ax,ay,bx,by), dot(ax,ay,bx,by)); } #define curr( P , i ) P[ (i) % P.size() ] #define next( P , i ) P[ (i+1) % P.size() ] #define prev( P , i ) P[ (i+P.size()-1) % P.size() ] bool is_convex( const polygon & P ) { for( int i = 0 ; i < P.size() ; i ++ ) if( ccw( prev( P , i ) , curr( P , i ) , next( P , i ) ) > 0 ) return false; return true; } vector < point > convex_hull ( vector < point > ps ) { int n = ps.size(), k = 0; sort( ps.begin() , ps.end() ); vector < point > ch ( 2*n ); for( int i = 0 ; i < n ; ch[k++] = ps[i++] ) //lower hull while( k >= 2 && ccw( ch[k-2] , ch[k-1] , ps[i] ) <= 0 ) --k; for( int i = n - 2 , t = k + 1 ; i >= 0 ; ch[k++] = ps[i--] ) //upper hull while( k >= t && ccw( ch[k-2] , ch[k-1] , ps[i] ) <= 0 ) --k; ch.resize(k-1); return ch; } double area2( const polygon& P ) { double A = 0; for( int i = 0 ; i < P.size() ; ++ i ) A += cross( curr( P , i ), next( P , i ) ); return A / 2; } bool intersectSS (const L &s, const L &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 intersectLL( L &l , L&m , point &x ) { if( !intersectSS( l , m ) ) return false; 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 )//same line x = m[0]; if( abs(A) < EPS )//parallel line return false; x = m[0] + B/A * ( m[1] - m[0] ); return true; } int contains( const polygon& P , const point& p ) { bool in = false; for( int i = 0 ; i < P.size() ; i ++ ) { point a = curr( P , i ); a -= p; point b = next( P , i ); b -= p; if (imag (a) > imag (b)) swap (a, b); if (imag (a) <= 0 && 0 < imag (b)) if (cross (a, b) < 0) in = !in; if (cross (a, b) == 0 && dot (a, b) <= 0) return 2; } return in ? 1 : 0; } point get() { double a, b; cin >> a >> b; return point( a , b ); } bool in( point a[3] , point b[3] ) { polygon aa; For( i , 3 ) aa.push_back( a[i] ); int cnt = 0; For( i , 3 ) if( contains( aa , b[i] ) == 1 ) cnt ++; return cnt == 3; } int f( polygon p ) { set < point > st; For( i , p.size() ) st.insert( p[i] ); return st.size(); } int main() { int t; point a[3], b[3]; cin >> t; while( t -- ) { polygon pp; For( i , 3 ) a[i] = get(); For( i , 3 ) b[i] = get(); L l1[3] = { L( a[0] , a[1] ) , L( a[0] , a[2] ) , L( a[1] , a[2] ) }; L l2[3] = { L( b[0] , b[1] ) , L( b[0] , b[2] ) , L( b[1] , b[2] ) }; point x; For( i , 3 ) For( j , 3 ) if( intersectLL( l1[i] , l2[j] , x ) ) pp.push_back( x ); polygon aa, bb; For( i , 3 ) aa.push_back( a[i] ), bb.push_back( b[i] ); For( i , 3 ) { if( contains( aa , b[i] ) == 1 ) pp.push_back( b[i] ); if( contains( bb , a[i] ) == 1 ) pp.push_back( a[i] ); } if( f( pp ) < 3 ) cout << "0.00" << endl; else { pp = convex_hull( pp ); cout << setprecision(2) << fixed << area2( pp ) << endl; } } return 0; }