#include <iostream>
using namespace std;
int main(){
	int n;
	int w;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> w;
		cout << "Case " << i+1 << ":" << endl;
		for(int j=0;j<10;j++){
			w = w*w;
			w /= 100;
			w = w % 10000;
			cout << w << endl;
		}
	}
}