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 Scala (judge verdict: Accepted)

import Math._
object Main extends App {
  val n = readLine().toInt

  for (i <- 0 until n) {
    val Seq(x1, y1, x2, y2, x3, y3) = readLine().split(' ').map(_.toDouble).toList
    val l1 = pow(x2 - x3, 2) + pow(y2 - y3, 2)
    val l2 = pow(x3 - x1, 2) + pow(y3 - y1, 2)
    val l3 = pow(x1 - x2, 2) + pow(y1 - y2, 2)

    val G1 = l1*(l2 + l3 - l1)
    val G2 = l2*(l3 + l1 - l2)
    val G3 = l3*(l1 + l2 - l3)

    val px = (G1 * x1 + G2 * x2 + G3 * x3) / (G1 + G2 + G3)
    val py = (G1 * y1 + G2 * y2 + G3 * y3) / (G1 + G2 + G3)

    val u1 = sqrt(l1)
    val u2 = sqrt(l2)
    val u3 = sqrt(l3)

    val r = (u1 * u2 * u3) / sqrt((u1 + u2 + u3) * (-u1 + u2 + u3) * (u1 - u2 + u3) * (u1 + u2 - u3))

    println("%.3f %.3f %.3f".format(px, py, r))
  }
}