#include<iostream>
#include<cstdio>
using namespace std;

#define rep(i, n)for((i) = 0;(i) < (n);++(i))

int main(void){
	int i, j, q, n;
	scanf("%d", &q);
	rep(i, q){
		printf("Case %d:\n", i + 1);
		scanf("%d", &n);
		for(int t = 10;t--;){
			n = (n * n / 100) % 10000;
			printf("%d\n", n);
		}
	}
}