#include <iostream>
using namespace std;

int main() {
    int d;
    cin >> d;
    for (int i = 1; i <= d; i++) {
        int n;
        cin >> n;
        cout << "Case " << i << ":" << endl;
        for (int j = 0; j < 10; j++) {
            n *= n;
            n /= 100;
            n %= 10000;
            cout << n << endl;
        }
    }
    return 0;
}