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

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