#include <stdio.h>

int GenNextRand(int s);

int main(void){
    int seed,next;
    int n;
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%d",&seed);
        printf("Case %d:\n",i+1);
        for (int j=0; j<10; j++){
            next = GenNextRand(seed);
            printf("%d\n", next);
            seed = next;
        }
    }
    
    return 0;
}

int GenNextRand(int s){
    int tmp;
    
    tmp = s*s;
    return (tmp/100) % 10000;
}