#include<iostream>
#include<sstream>
#include <iomanip>
using namespace std;

int main()
{
	int n, count = 0, i, j, p;
	stringstream ss;
	cin>>n;
	while (cin>>n) {
		cout<<"Case "<<++count<<":"<<endl;
		for (i = 0; i < 10; i++) {
			ss.str("");
			ss<<setw(8)<<setfill('0')<<right<<n*n<<endl;
			n = 0; p = 1;
			for (j = 0; j < 4; j++) {
				n += p*(ss.str()[5-j]-'0');
				p *= 10;
			}
			cout<<n<<endl;
		}
	}
	return 0;
}