#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int n;
	int value;
	
	cin >> n;
	for (int j = 0; j < n; j++){
		cin >> value;
		cout << "Case " << j + 1 << ':' << endl;
		for (int i = 0; i < 10; i++){
			value = pow(value, 2);
			value /= 100;
			value %= 10000;
			cout << value << endl;
		}
	}
	return (0);
}