// Arup Guha
// 5/20/2021
// Solution to 2021 Code Jam Round 1B Problem A: Broken Clock

import java.util.*;
import java.math.*;

public class Solution {

	public static long[] vals;
	
	// Important numbers.
	final public static long REV = 360L*12L*10000000000L;
	final public static BigInteger MOD = new BigInteger(""+REV);
	final public static BigInteger ELEVEN = new BigInteger("11");
	final public static BigInteger SEVEN19 = new BigInteger("719");
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
			
			// Get the array.
			vals = new long[3];
			for (int i=0; i<3; i++)
				vals[i] = stdin.nextLong();
			
			// Solve and extract the answer.
			long res = go(new int[3], new boolean[3], 0);
			long ns = res%1000000000;
			res /= 1000000000;
			long sec = res%60;
			res /= 60;
			long min = res%60;
			res /= 60;
			
			// Ta da!
			System.out.println("Case #"+loop+": "+res+" "+min+" "+sec+" "+ns);
		}
	}
	
	// Return an answer for this permutation with the first k items fixed.
	public static long go(int[] perm, boolean[] used, int k) {
		
		// Done filling, evaluate.
		if (k == 3) return solve(perm);
		
		// Try each item in slot k.
		for (int i=0; i<3; i++) {
			if (!used[i]) {
				perm[k] = i;
				used[i] = true;
				long tmp = go(perm, used, k+1);
				if (tmp != -1) return tmp;
				used[i] = false;
			}
		}
		
		// No solution.
		return -1;
	}
	
	// Returns the answer for this permutation.
	public static long solve(int[] perm) {
		
		// Get differences. No matter the offset, the difference is what matters.
		long hrAngle = vals[perm[0]];
		long minAngle = vals[perm[1]];
		long secAngle = vals[perm[2]];
		long x1 = minAngle-hrAngle;
		if (x1 < 0) x1 += REV;
		long x2 = secAngle-hrAngle;
		if (x2 < 0) x2 += REV;

		// The mod inverses we need. 
		BigInteger inv11 = ELEVEN.modInverse(MOD);
		BigInteger inv719 = SEVEN19.modInverse(MOD);
		
		// Solve for ticks past midnight using minute and hour hand.
		// The diff between min and hour hands is 11X, where X is the # of ticks.
		BigInteger myX1 = new BigInteger(""+x1);
		myX1 = inv11.multiply(myX1);
		myX1 = myX1.mod(MOD);
		
		// Solve for ticks past midnught using second and hour hand.
		// The diff between sec and hour hands is 719X, where X is the # of ticks.
		BigInteger myX2 = new BigInteger(""+x2);
		myX2 = inv719.multiply(myX2);
		myX2 = myX2.mod(MOD);

		// These have to be consistent to be a potential solution.
		if (myX1.equals(myX2)) return myX1.longValue();
		
		// Impossible code.
		return -1;
	}
}
