#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

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