#include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		int Num;
		cin >> Num;
		cout << "Case " << i << ":" << endl;
		for(int j = 0; j < 10; ++j)
		{
			Num *= Num;
			Num %= 1000000;
			Num /= 100;
			cout << Num << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}