#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
string to_string_keta(const long long int l, const int keta) {
	ostringstream oss;

	oss << std::setw(keta) << std::setfill('0') << l;

	return oss.str();
}

int main() {
	int num = 0;
	int N;

	while (cin >> N) {
		if (num) {
			cout << "Case " << num << ":" << endl;
			for (int i = 0; i < 10; ++i) {
				N *= N;
				string st = to_string_keta(N, 8);
				N = stoi(st.substr(2, 4));
				cout << N << endl;
			}
		}
		num++;
	}
	return 0;
}