#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;

int next(int x) {
    return ((x * x) / 100) % 10000;
}

int main() {
    int n, s;
    cin >> n;
    for (int i=1; i<=n; ++i) {
        cout << "Case " << i << ":" << endl;
        cin >> s;
        for (int j=0; j<10; ++j) {
            s = next(s);
            cout << s << endl;
        }
    }
    return 0;
}