#include <iostream>

using namespace std;

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

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