#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n;
	for(int times=0;times<n;times++){
		cout<<"Case "<<times+1<<':'<<endl;
		cin>>x;
		for(int i=0;i<10;i++){
			x=x*x%1000000/100;
			cout<<x<<endl;
		}
	}
}