#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;

int middle_square(int s) {
	return ((s * s) / 100) % 10000;
}

void AOJ0137(int x)
{
	int s;
	cin >> s;
	cout << "Case " << x << ":" << endl;
	REP(i, 10) {
		cout << (s = middle_square(s)) << endl;
	}
	return;
}

int main()
{
	int d;
	cin >> d;
	REP(i, d) AOJ0137(i + 1);

	return 0;
}