/**
 * Profits.java
 * Logan Kriete
 * 7/25/10
 * Solution for Profits BHCSI 2010 contest #3 problem
 */

import java.util.*;
import java.io.*;

public class profits {

    public static void main(String[] args) throws FileNotFoundException {
    	
    	// create our file scanner
    	File f = new File("profits.in");
    	Scanner fin = new Scanner(f);
    	
    	// find out how many years we're processing
    	int numYears = fin.nextInt();
    	
    	// loop through numYears times
    	for (int year = 2010; year < 2010+numYears; year++) {
    		
    		System.out.println("Results for " + year + ":");
    		
    		// read in how many stores we're processing data for
			int numStores = fin.nextInt();
    		
    		// create our 2D array to hold profit data
    		// the array is numStores*12 because we'll need to hold data for each month of each store
    		double[][] profitData = new double[numStores][12];
    		
    		// read in data, store by store, month by month
    		for (int j = 0; j < numStores; j++)
    			for (int k = 0; k < 12; k++)
    				profitData[j][k] = fin.nextDouble();
    				
    		/* START CALCULATIONS
    		** To make this a bit easier as a solution, I've
    		** broken each calculation up into its own section,
    		** although one can easily do all the calculations
    		** within only two loops (or even above without
    		** even reading the data into a variable).
    		*/
    				
    		// first calculation: averages for each store
    		for (int j = 0; j < numStores; j++) {
    			double storeTotal = 0; // sum up store's monthly profits for the yearly total
    			for (int k = 0; k < 12; k++)
    				storeTotal += profitData[j][k];
    				
    			// output average
    			System.out.println("Store #" + (j+1) + " monthly average was $" + (storeTotal/12));
    		}
    		
    		// second calculation: least-profitable store based on totals
    		int lowestStore = 0; // the number of our least-profitable store
    		double lowestTotal = 0; // keep track of the lowest total
    		for (int j = 0; j < numStores; j++) {
    			double storeTotal = 0; // sum up store's monthly profits for the yearly totals
    			for (int k = 0; k < 12; k++) {
    				storeTotal += profitData[j][k];
    			}
    			
    			// flag for the first run-through, set the lowest
    			if (j == 0) lowestTotal = storeTotal;
    			
    			// if this store has a lower yearly profit than the current lowest, reset their values
    			if (storeTotal < lowestTotal) {
    				lowestTotal = storeTotal;
    				lowestStore = j;
    			}
    		} // output answer
    		System.out.println("The least-profitable store based on yearly totals was store #" + (lowestStore+1) + ", with a profit of $" + lowestTotal);
    		
    		// third calculation: store with highest monthly sale
    		int highestStore = 0; // the number of our highest-monthly store
    		double highestTotal = 0; // keep track of the highest total
    		for (int j = 0; j < numStores; j++) {    			
    			for (int k = 0; k < 12; k++)
    				if (profitData[j][k] > highestTotal) {
    					highestTotal = profitData[j][k];
    					highestStore = j;
    				}
    		} // ouput answer
    		System.out.println("The store with the highest monthly sale was store #" + (highestStore+1) + ", with a sale of $" + highestTotal);
    		
    		// fourth calculation: December total across all stores
    		double decemberTotal = 0;
    		for (int j = 0; j < numStores; j++)
    			decemberTotal += profitData[j][11];
    		System.out.println("The total for all stores over the month of December was $" + decemberTotal);
    		
    		// blank line to separate output
    		System.out.println();
    		
    	}
    	
    	fin.close();
    	
    }
    
}