// 2011/01/11 Tazoe

#include <iostream>
using namespace std;

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

	for(int x=1; x<=n; x++){
		int s;
		cin >> s;

		cout << "Case " << x << ":" << endl;

		for(int i=0; i<10; i++){
			s = s*s;
			s = (s/100)%10000;
			cout << s << endl;
		}
	}

	return 0;
}