// Jared Wasserman and Tatiana Viecco
// 9/30/2011
// COP 3223H Section 201
// Friday Problem Week 4: It Makes No Difference in the End
// Returns sequences based on difference between numbers in sequence

#include <stdio.h>
#include <math.h>

int main ()
{

    // Open the input file
    FILE *ifp = fopen("subtract.in", "r");

    // Declare variables for test cases
    int test_cases, current_case;

    // Read in test cases
    fscanf(ifp, "%d", &test_cases);

    // Loop through test cases
    for (current_case = 1; current_case <= test_cases; current_case++)
    {

        // Declare each number
        int num_1, num_2, num_3, num_4;

        // Read in each number
        fscanf(ifp, "%d%d%d%d", &num_1, &num_2, &num_3, &num_4);

        // Print current test case and original values
        printf("Case %d:\n", current_case);
        printf("%d %d %d %d\n", num_1, num_2, num_3, num_4);

        // Loop through numbers until they all equal each other
        while (num_1 != num_2 || num_2 != num_3 || num_3 != num_4)
        {
            // Subtracts neighbor value from original value before and after it in the sequence
            int temp = num_1;
            num_1 = abs(num_1 - num_2);
            num_2 = abs(num_2 - num_3);
            num_3 = abs(num_3 - num_4);
            num_4 = abs(num_4 - temp);

            printf("%d %d %d %d\n", num_1, num_2, num_3, num_4);
        }

        printf("\n");
    }

    // Close input file
    fclose(ifp);
    return 0;

}
