Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Circumscribed Circle of A Triangle.

Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.

Input

Input consists of several datasets. In the first line, the number of datasets $n$ is given. Each dataset consists of:

$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$

in a line. All the input are real numbers.

Output

For each dataset, print $p_x$, $p_y$ and $r$ separated by a space in a line. Print the solution to three places of decimals. Round off the solution to three decimal places.

Constraints

$-100 \leq x_1, y_1, x_2, y_2, x_3, y_3 \leq 100$

$ n \leq 20$

Sample Input

1
0.0 0.0 2.0 0.0 2.0 2.0

Output for the Sample Input

1.000 1.000 1.414

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;

static class CircumscribedCircleOfATriangle
{
    static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(
        this IEnumerable<TFirst> source,
        IEnumerable<TSecond> second,
        Func<TFirst, TSecond, TResult> func)
    {
        var q1 = new Queue<TFirst>( source );
        var q2 = new Queue<TSecond>( second );
        while ( q1.Any() && q2.Any() )
            yield return func( q1.Dequeue(), q2.Dequeue() );
    }

    static void Main()
    {
        Func<
            IEnumerable<double>, 
            IEnumerable<double>, 
            Func<double, double, double>, 
            double[]>
            calc = (a, b, f) => a.Zip( b, f ).ToArray();
        var q =
            from n in Enumerable.Repeat( 0, int.Parse( Console.ReadLine() ) )
            let t = Console.ReadLine()
                .Split( ' ' )
                .Zip( new[] { 0, 0, 1, 1, 2, 2 }, 
                    (pc, p) => new { pc, p } )
                .GroupBy( e => e.p, e => e.pc )
                .Select( p => p.Select( double.Parse ).ToArray() )
                .ToArray()
            let a = t.First()
            let v = t.Skip( 1 )
                .Select( p => calc( p, a, (x, y) => x - y ) )
                .Select( ap => new
                {
                    m = ap.Select( c => c / 2 ),
                    tp = new[] { -ap[1], ap[0] }
                } )
                .ToArray()

            let s = calc( v[0].m, v[0].tp, (x, y) => x + y )
            let cross = new[] 
                { 
                    calc( v[1].m, v[0].m, (x, y) => x - y ),
                    calc( s, v[1].m, (x, y) => x - y )
                }
                .Select( x => v[1].tp[0] * x[1] - v[1].tp[1] * x[0] )
                .ToArray()
            let k = cross[0] / cross.Sum()

            let ag = calc( v[0].m, s, (x, y) => x + k * ( y - x ) )
            let og = calc( ag, a, (x, y) => x + y )
            let r = Math.Sqrt( ag[0] * ag[0] + ag[1] * ag[1] )

            select string.Format( "{0:0.000} {1:0.000} {2:0.000}\n", og[0], og[1], r );
        Console.Write( new string( q.SelectMany( _ => _ ).ToArray() ) );
    }
}