#include<iostream>
using namespace std;
int x, n;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cout << "Case " << i << ':' << endl;
		cin >> x;
		for (int j = 1; j <= 10; j++) {
			x = ((x*x) % 1000000) / 100;
			cout << x << endl;
		}
	}
}