package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileReader;
/**
 * Base class to provide a framework for Google Code Jam type of problems and avoid redundant tasks 
 * @author nitin
 */
public class BaseSolution {
         
	/**
	 * Used to write log for debugging
	 */
	PrintWriter logger;
	/**
	 * to print solution to output.txt
	 */
	PrintWriter output;
	/**
	 * used to read the problem file
	 */
	BufferedReader br;
	boolean logToConsole = false;
	public void setLogToConsole(boolean flag){
		logToConsole = flag;
	}
	public void start(String probPath) throws Exception {
	        logger = new PrintWriter(new FileWriter("debug.txt"));
		output = new PrintWriter(new FileWriter("output.txt"));
                br =  new BufferedReader(new FileReader(probPath));
		init();
		closeAll();
	}
	public void logTo(PrintWriter pw){
		logger = pw;
	}
	public void init() throws Exception{
		int num_test_cases = readInt();
		log("Total test cases : "+num_test_cases);
		for(int i=0;i<num_test_cases;i++)
		{
			solveTestCase(i,num_test_cases);
		}
	}
	public void solveTestCase(int index,int total_test_cases) throws Exception{
		solveTestCase(index);
	}
	public String solveTestCase() throws Exception{
              return "Solve method not implemented";
	}
	public void solveTestCase(int index) throws Exception{
	       printSol(index,solveTestCase());
	}
	public String readLine() throws Exception{
		return br.readLine();
	}
	public int readInt() throws Exception{
		return Integer.parseInt(readLine());
	}
	public void finalize() throws Exception{
		if(logger!=null){
			logger.close();
		}
		if(output!=null){
			output.close();
		}
		if(br!=null){
			br.close();
		}
	}
	public void closeAll() throws Exception{
		try{
		if(logger!=null){
		logger.close();
		logger = null;
		}
		}catch(Exception e){
			System.out.println("Exception "+e);
		}
		finally{
		if(output!=null){
		output.close();
		output = null;
		if(br!=null)
		{
			br.close();
		}
		}
		}
	}
	public void printSol(int i,String str){
		printSol("Case #"+(i+1)+": "+str);
	}
	public void printSol(String str){
		output.println(str);
	}
	public void log(String str){
                if(1==1) return;
		if(logToConsole==false){
			logger.println(str);
		} else {
			System.out.println(str);
		}
	}
       
	
}
