#include <iostream>
using namespace std;

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