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;

public class Hello
{
    public static void Main()
    {
        Calc calc = new Calc();
        List<double[]> ans = new List<double[]>();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            List<double> input = new List<double>();
            double[] ans2 = new double[3];
            input = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
            ans2 = calc.Triangle(input);
            ans.Add(ans2);
        }

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine("{0:f3} {1:f3} {2:f3}", ans[i][0], ans[i][1], ans[i][2]);
        }
    }
  
}
class Calc
{
    internal double[] Triangle(List<double> input)
    {
        double px, py, r;
        double[] ans = new double[3];

        double x1 = input[0];    double y1 = input[1];
        double x2 = input[2];    double y2 = input[3];
        double x3 = input[4];    double y3 = input[5];

        double a = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
        double b = Math.Sqrt(Math.Pow(x3 - x1, 2) + Math.Pow(y3 - y1, 2));
        double c = Math.Sqrt(Math.Pow(x3 - x2, 2) + Math.Pow(y3 - y2, 2));
        double cos_theta = (Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / ((double)2 * a * b);
        double sin_theta = Math.Sqrt(1 - Math.Pow(cos_theta, 2));

        if (a == 0 && b == 0 && c == 0)
        {
            px = x1;
            py = y1;
            r = 0;
        }
        else if (c==0)
        {
            px = (x2 - x1) / (double)2;
            py = (y2 - y1) / (double)2;
            r = Math.Sqrt(Math.Pow(px, 2) + Math.Pow(py, 2)) / (double)2;
        }
        else if (sin_theta == 0)
        {
            px = Double.NaN;
            py = Double.NaN;
            r = Double.NaN;
        }
        else
        {
            double[] vector12 = new double[2] {x2 - x1, y2 - y1};
            double[] vector_v = new double[2] {-(y3 - y2), x3 - x2};
            double magnitude = Math.Sqrt(Math.Pow(vector_v[0], 2) + Math.Pow(vector_v[1], 2));
            double inner_product = vector12[0] * vector_v[0] + vector12[1] * vector_v[1];

            if (inner_product > 0)
            {
                vector_v[0] = -vector_v[0] / magnitude;
                vector_v[1] = -vector_v[1] / magnitude;
            }
            else
            {
                vector_v[0] = vector_v[0] / magnitude;
                vector_v[1] = vector_v[1] / magnitude;
            }

            r = c / ((double)2 * sin_theta);

            double cx = (x3 + x2) / (double)2;
            double cy = (y3 + y2) / (double)2;
            px = cx + r * cos_theta * vector_v[0];
            py = cy + r * cos_theta * vector_v[1];
        }

        ans[0] = Math.Round(px, 3, MidpointRounding.AwayFromZero);
        ans[1] = Math.Round(py, 3, MidpointRounding.AwayFromZero);
        ans[2] = Math.Round(r, 3, MidpointRounding.AwayFromZero);
        return ans;
    }
}