#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
	int n;
	long s;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		cout<<"Case "<<i<<":"<<endl;
		for(int j=0;j<10;j++){
			s = s*s;
			s /= 100;
			if(s>=10000) s = s%10000;
			cout<<s<<endl;
		}
	}

	return 0;
}