#include <iostream>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	
	rep(i,n)
	{
		ll a;
		cin >> a;
	
		cout << "Case " << i+1 << ":" << endl;
		rep(j,10)
		{
			a *= a;
			a /= 100;
			ll b = a/10000;
			b *= 10000;
			a -= b;
			cout << a << endl;
		}
	}
	return 0;
}