#include<iostream>
using namespace std;

int main(void){
	
	int n,s;
	int s2;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		cout<<"Case "<<i<<":"<<endl;
		for(int k=0;k<10;k++){
			s2=s*s;
			s2/=100;
			s=0;
			for(int j=1;j<=1000;j*=10){
				s+=(s2%10)*j;
				s2/=10;
			}
			cout<<s<<endl;
		}
	}
	return 0;
}