#include <iostream>

using namespace std;

typedef long long ll;

int main(){
	ll n, s, ans;
	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;
			s %= 1000000;
			s /= 100;
			cout << s << endl;
		}
	}
}