#include<iostream>
using namespace std;
int main(void){
  int n,m,i=1,j;
  for(cin>>m;i<=m;i++){
    cout<<"Case "<<i<<":"<<endl;
    for(cin>>n,j=0;j<10;j++){
      n=((n*n)%1000000)/100;
      cout<<n<<endl;
    }
  }
}