// Jared Wasserman and Stephen Maguire
// 10/7/2011
// COP 3223H Section 201
// Friday Problem: Kalamazoo Train Crazyness

#include <stdio.h>

int main ()
{

    // Open file
    FILE *ifp = fopen("kalamazoo.in", "r");

    // Read in test cases
    int total_cases, current_case;
    fscanf(ifp, "%d", &total_cases);

    // Loop through test cases
    for (current_case = 1; current_case <= total_cases; current_case++)
    {
        // Read in number of cars
        int num_cars, current_car;
        fscanf(ifp, "%d", &num_cars);

        // Declare array for train
        double train_weight[100];

        // Zero out the array
        for (current_car = 0; current_car < 100; current_car++)
        {
            train_weight[current_car] = 0;
        }

        // Read in car weights for train_weight array
        for (current_car = 0; current_car < num_cars; current_car++)
        {
            fscanf(ifp, "%lf", &train_weight[current_car]);
        }

        // Change the end loop condition so that if there are less than 3 cars, it still goes through the loop once
        if (num_cars < 3)
        {
            num_cars = 3;
        }

        // Set flag variable too_heavy to false
        int too_heavy = 0;

        // Check each consecutive group of three cars to see if their combined weights are greater than 1000
        // If the combined weight is greater than 1000, set too_heavy to true
        for(current_car = 0; current_car <= (num_cars - 3); current_car++)
        {
            if (train_weight[current_car] + train_weight[current_car + 1] + train_weight[current_car + 2] > 1000)
            {
                too_heavy = 1;
                break;
            }
        }

        // Print out train number
        printf("Train %d: ", current_case);

        // Print out results for each case
        if (too_heavy)
        {
            printf("Kalamazoo is doomed!\n");
        }
        else
        {
            printf("Just another day at the trainyard.\n");
        }
    }

    // Close the input file
    fclose(ifp);
    return 0;
}
