#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;
		int ans = 0;
		for(int j = 0; j < 10; ++j)
		{
			ans = num * num;
			ans %= 1000000;
			ans /= 100;
			num = ans;
			cout << ans << endl;
		}
	}
}

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