#include<iostream>
#include<cstdio>
using namespace std;

int main(){
	int n;
	int s;
	cin >> n;

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

}