#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int N;
	cin >> N;
	REP(n, N) {
		printf("Case %d:\n", n + 1);
		int s;
		cin >> s;
		REP(i, 10) {
			s = (s * s) / 100 % 10000;
			cout << s << endl;
		}
	}
	return 0;
}