#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n,s;
	cin>>n;
	rep(i,0,n){
		cin>>s;
		o("Case "<<i+1<<":");
		rep(j,0,10){
			s=s*s/100;
			s%=10000;
			printf("%d\n",s);
		}
	}
}