#include <iostream>

using namespace std;

int next_num(int s) {
    int square = s * s;
    return (square % 1000000) / 100;
}

void print_random(int s) {
    int prev = s;
    for (int i = 0; i < 10; i++) {
        prev = next_num(prev);
        cout << prev << endl;
    }
}

int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        int s; cin >> s;
        cout << "Case " << i << ":\n";
        print_random(s);
    }
    return 0;
}