#include<iostream>
using namespace std;
void solve(int i) {
	int k; cin >> k;
	cout << "Case " << i << ":\n";
	for (int i = 0; i < 10; i++) {
		k = (k*k / 100) % 10000;
		cout << k << endl;
	}
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		solve(i + 1);
	}
}