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: Time Limit Exceeded)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>

struct node{
	double x;
	double y;
};

struct node a, b, c, c_in;
struct node a_mid, b_mid, c_mid;
int debug=1;

void solve(double a, double b, double c, double d, double e, double f){
	double ratio;
	double x, y;

	ratio = 1 /(a*e - b*d);
	x = ratio * (e * c + -1 * b * f);
	y = ratio * (-1 * d * c + a * f);
	if(x == 0){
		x = 0;
	}
	if(y == 0){
		y = 0;
	}

	printf("%.3f %.3f", x, y);
	return ;
}

int main(void){
	int i, n;
	double a_len, b_len, c_len, tmp, s, sin_a, r;
	double a_angle, b_angle, c_angle;

	scanf("%d", &n);

	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf", 
			&(a.x), &(a.y), &(b.x), &(b.y), &(c.x), &(c.y));

		//calc a,b,c
		a_len = sqrt(pow(b.x - c.x, 2) + pow(b.y - c.y, 2));
		if(debug) printf("a:length %.3f\n", a_len);
		b_len = sqrt(pow(a.x - c.x, 2) + pow(a.y - c.y, 2));
		if(debug) printf("b:length %.3f\n", b_len);
		c_len = sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));
		if(debug) printf("c:length %.3f\n", c_len);

		//heron
		tmp = 0.5 * (a_len + b_len + c_len);
		s = sqrt(tmp * (tmp - a_len) * (tmp - b_len) * (tmp - c_len));

		//calc sin A
		sin_a = (2 * s) / (b_len * c_len);

		//calc Radius
		r = (a_len / sin_a) * 0.5;
		if(debug) printf("radius = %.3f\n", r);

		//ツ外ツ心ツづーツ仰づ淞づゥ
		//bツづ個傾ツつォツづ陳点
		if(c.y == a.y ){	
			b_angle = HUGE_VAL;
		}else if(c.x == a.x){
			b_angle = 0;
		}else{
			b_angle = -1 / ((c.y - a.y) / (c.x - a.x));
		}
		b_mid.x = (a.x + c.x) / 2;
		b_mid.y = (a.y + c.y) / 2;
		if(debug) printf("b:angle = %.3f, x = %.3f y = %.3f\n", b_angle, b_mid.x, b_mid.y);

		//cツづ個傾ツつォツづ陳点
		if(a.y == b.y ){	
			c_angle = HUGE_VAL;
		}else if(a.x == b.x){
			c_angle = 0;
		}else{
			c_angle = -1 / ((b.y - a.y) / (b.x - a.x));
		}
		c_mid.x = (a.x + b.x) / 2;
		c_mid.y = (a.y + b.y) / 2;
		if(debug) printf("c:angle = %.3f, x = %.3f y = %.3f\n", c_angle, c_mid.x, c_mid.y);

		if(b_angle == 0){
			c_in.y = b_mid.y;
			c_in.x = ((c_in.y - c_mid.y) / c_angle) + c_mid.x;
			printf("%.3f %.3f", c_in.x, c_in.y);
		}else if(c_angle == 0){
			c_in.y = c_mid.y;
			c_in.x = ((c_in.y - b_mid.y) / b_angle) + b_mid.y;
			printf("%.3f %.3f", c_in.x, c_in.y);
		}else if(b_angle == HUGE_VAL){
			c_in.x = b_mid.x;
			c_in.y = c_angle * (c_in.x - c_mid.x) + c_mid.y;
			printf("%.3f %.3f", c_in.x, c_in.y);
		}else if(c_angle == HUGE_VAL){
			c_in.x = c_mid.x;
			c_in.y = b_angle * (c_in.x - b_mid.x) + b_mid.y;
			printf("%.3f %.3f ", c_in.x, c_in.y);
		}else{
			solve(-1 * b_angle, 1, b_angle * -1 * b_mid.x + b_mid.y,
				  -1 * c_angle, 1, c_angle * -1 * c_mid.x + c_mid.y);
		}

		printf("%.3f\n", r);
		if(debug) while(1){}
	}
	return 0;
}