#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int n, s;
	cin >> n;
	rep(i,n) {
		cin >> s;
		cout << "Case " << i+1 << ":" << endl;
		rep(j,10) {
			s *= s;
			s /= 100;
			int ns = s/10000 * 10000;
			s -= ns;
			cout << s << endl;
		}
	}
	return 0;
}