#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,s;
	cin>>n;
	for(int u=0;u<n;u++){
		cin>>s;
		cout<<"Case "<<u+1<<":"<<endl;
		for(int o=0;o<10;o++){
			s=s*s%1000000/100;
			cout<<s<<endl;
		}
	}
	return 0;
}