#include <cstdio>

using namespace std;

int main()
{
    int d, s;
    scanf( "%d\n", &d );
    for( int i = 0; i < d; i++ )
    {
        scanf( "%d\n", &s );
        printf( "Case %d:\n", i + 1 );
        for( int j = 0; j < 10; j++ )
        {
            s = s * s;
            s /= 100;
            s %= 10000;
            printf( "%d\n", s );
        }
    }    
    return 0;
}
