#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	for (int c = 0; c < n; ++c)
	{
		int s;
		scanf("%d", &s);
		printf("Case %d:\n", c+1);
		for (int i = 0; i < 10; ++i)
			printf("%d\n", s = s*s/100 % 10000);
	}

	return 0;
}