#include<bits/stdc++.h>
using namespace std;
void serch(int n,int now)
{
    n=n%1000000/100;
    cout<<n<<endl;
    if(now<10)serch(n*n,now+1);
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int num;
        cin>>num;
        cout<<"Case "<<i<<':'<<endl;
        serch(num*num,1);
    }
}