#include <iostream>
using namespace std;



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

    return 0;
}