#include<iostream>
using namespace std;

int rand (int a){
	return a=a*a/100-a*a/1000000*10000;
}

int main(){
	int d,l;
	
	cin>>d;
	for(int i=1;i<=d;i++){
		cin>>l;
		cout<<"case "<<i<<":"<<endl;
		for(int j=0;j<10;j++){
			l=rand(l);
			cout<<l<<endl;
		}
	}
}	