#include<stdio.h>
int main()
{
	int x=0,n,s,i;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&s);
		printf("Case %d:\n",++x);
		for(i=0;i<10;++i)
			printf("%d\n",(s= (s*s)/100%10000));
	}
	return 0;
}