#include <iostream>

class Rand {
public:
	Rand(const int &in = 123) :init{ in } {};
	int operator()() {
		return init = next(init);
	}
private:
	int init;
	int next(const int &i) const {
		return (i * i) / 100 % 10000;
	}
};

int main() {
	int n;
	std::cin >> n;
	for (auto c = 1; c <= n; ++c) {
		int init;
		std::cin >> init;
		Rand rand(init);
		std::cout << "Case " << c << ":\n";
		for (auto i = 0; i < 10; ++i) {
			std::cout << rand() << '\n';
		}
	}
	return 0;
}