#include<iostream>
using namespace std;

int jyo(int);

int main(){
  int s,t,u;
  cin>>s;
  for(int i=1;i<=s;i++){
    cin>>u;
    cout<<"Case "<<i<< ":"<<endl;
    for(int j=0;j<10;j++){
      t=jyo(u);
      cout<<t/100<<endl;
      u=t/100;
    }
  }
  return 0;
}

int jyo(int n){
  n*=n;
  n-=(n/10000000)*10000000;
  n-=(n/1000000)*1000000;
  return n;
}