#include <stdio.h>
#include <iostream>

using namespace std;

void kei(int d, int f[],int r)
{
	for (int l = r; l < 10; l++) {
		f[l] += d % 10;
		if (f[l] >= 10 && l != 9) {
			f[l+1] += f[l] / 10;
			f[l] %= 10;
		}
		d /= 10;
	}
	return;
}

void keisan(int a, int b) 
{
	if (b == 0) {
		return;
	} else {
		int t;
		int y;
		int r[10] = {0};
		int x;
		y = a;
		for (int j = 0; j < 10; j++) {
			x = a * (y % 10);
			kei(x,r,j);
			y /= 10;
		}
		t = r[2] + r[3] * 10 + r[4] * 100 + r[5] * 1000;
		cout << t << endl;
		keisan(t,b-1);
	}
}

int main() {
	int n;
	int k;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> k;
		cout << "Case " << i+1 << ":" << endl;
		keisan(k,10);
	}
	return 0;
}