// Arup Guha
// 2/20/06
// Solution to COP 3530 Spring 2006 Recitation #3 Problem A: Solving a System of Two Equations

import java.util.*;
import java.io.*;

public class TwoEquations {

  // Used to test if a value is close to 0. It's arbitrarily chosen.
  final static double EPSILON = 0.0000001;

  public static void main(String[] args) throws IOException {

    Scanner stdin = new Scanner(System.in);

    // Get the input file name.
    System.out.println("What is the input file name?");
    String filename = stdin.next();

    Scanner fin = new Scanner(new File(filename));

    // Read in the number of equations to process.
    int numeqs = fin.nextInt();

    // Process each equation.
    for (int i=1; i<=numeqs; i++) {

      // Structure to store each equation.
      float[][] eqs = new float[2][3];

      // Read in two equations.
      for (int j=0; j<2; j++)
        for (int k=0; k<3; k++)
          eqs[j][k] = fin.nextFloat();

      // Calculate the relevant determinants.
      float detmain = det(eqs[0][0], eqs[0][1], eqs[1][0], eqs[1][1]);
      float detx = det(eqs[0][2], eqs[0][1], eqs[1][2], eqs[1][1]);     
      float dety = det(eqs[0][0], eqs[0][2], eqs[1][0], eqs[1][2]);

      // If the main determinant is zero, since the problem specification says we will not
      // get any systems with an infinite number of solutions, we can assume that there will
      // be no solutions.
      if (Math.abs(detmain) < EPSILON)
        System.out.println("Test case "+i+": No solution.");

      // Otherwise, just use Cramer's rule to solve for both x and y.
      else {
        float x = detx/detmain;
        float y = dety/detmain;
        System.out.printf("Test case %d: The solution is (%.2f, %.2f).\n", i, x, y);
      }
    }
  }


  // Returns the determinant with a and b on the first row, c and d on the second, respectively.
  public static float det(float a, float b, float c, float d) {
    return a*d-b*c;
  }
}