#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	int n;
	unsigned int s;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		cin >> s;
		cout << "Case " << i + 1 << ":" << endl;

		for( int j = 0;j < 10;j++ ){
			s *= s;
			s /= 100;
			unsigned int a = s / 10000;
			a *= 10000;
			s -= a;

			cout << s << endl;
		}
	}
	

	return 0;
}