#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n;

    cin >> n;
    for (int x = 1; x <= n; x++) {
        int s;
        cin >> s;

        cout << "Case " << x << ":" << endl;
        for (int i = 0; i < 10; i++) {
            s = (s * s / 100) % 10000;
            cout << s << endl;
        }
    }
    return 0;
}