#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int main(void){

	int n;
	cin>>n;
	for(int i=0;i<n;i++){
        int s;
        cin>>s;
        cout<<"Case "<<i+1<<":"<<endl;
        for(int j=0;j<10;j++){

            s*=s;
            //cout<<s<<endl;
            s%=1000000;
            //cout<<s<<endl;
            s-=s%100;
            //cout<<s<<endl;
            s/=100;
            cout<<s<<endl;
        }
	}



	return 0;
}