#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

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