#include<iostream>
using namespace std;

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