#include <iostream>
using namespace std;

int d, s;

int main()
{
    cin >> d;

    for (int i = 0; i < d; i++) {
        cin >> s;

        cout << "Case " << i + 1 << ":" << endl;

        for (int j = 0; j < 10; j++) {
            s = s * s;

            s /= 100;
            s %= 10000;

            cout << s << endl;
        }
    }

    return 0;
}

