// Arup Guha
// 10/15/2013
// Solution to COP 3223 Program #7B: Ice (file in, file out)

#include <stdio.h>

#define CUP 7

int main() {

    // Open file.
    FILE* ifp = fopen("ice.in", "r");
    FILE* ofp = fopen("out.txt", "w");

    int numCases, loop;
    fscanf(ifp, "%d", &numCases);

    // Go through each case.
    for (loop=1; loop<=numCases; loop++) {

        // Case Header
        fprintf(ofp, "Session #%d:\n", loop);

        int bursts, i, curIce = 0, cupNum = 1;
        fscanf(ifp, "%d", &bursts);

        // Simulate bursts of ice for this case.
        for (i=0; i<bursts; i++) {

            // Process this burst.
            int ice;
            fscanf(ifp, "%d", &ice);
            curIce += ice;

            // Overflow!
            if (curIce > CUP) {
                fprintf(ofp, "   Cup #%d: %d cubes too many!\n", cupNum, curIce - CUP);
                curIce = 0;
                cupNum++;
            }

            // Perfect cup!
            else if (curIce == CUP) {
                fprintf(ofp, "   Cup #%d: Perfect!\n", cupNum);
                curIce = 0;
                cupNum++;
            }

        }

        // Only potentially the last cup doesn't fill.
        if (curIce > 0)
            fprintf(ofp, "   Cup #%d: Need %d more cubes!\n", cupNum, CUP - curIce);

        // Separate output for each case.
        fprintf(ofp, "\n");
    }

    fclose(ofp);
    fclose(ifp);
    return 0;
}
