#include <stdio.h>
int rand(int s);
int main(){
	 int i,s,j,n;
	 int a[8];
	 scanf("%d",&n);
	 j = n;
	 while(n--){
		 scanf("%d",&s);
		 printf("Case %d:\n",j-n);
		 for(i=0;i<10;i++){
			 s = rand(s);
			 printf("%d\n",s);
		 }
	 }

	 return 0;
}

int rand(int s){
	int i,r=0;
	s *= s;s /= 100;
	for(i=1;i<1001;i*=10){
		r += (s%10)*i;
		s /= 10;
	}
	return r;
}
			
 /* for(i=0;i<8;i++) a[i] = 0;
		 for(i=0;i<8;i++){ 
			 a[i] = s%10;
			 s/=10;
		 }
		 for(i=2;i<6;i++){
			 s += a[i]*j;
			 j*=10;
		 }*/