#include <bits/stdc++.h>

using namespace std;
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
typedef int64_t ll;

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

}

