#include <iostream>
using namespace std;

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