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


  }
}