//06
#include<iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cout<<"Case "<<i<<":"<<endl;
    int s;
    cin>>s;
    for(int j=0;j<10;j++){
      s=s*s%1000000/100;
      cout<<s<<endl;
    }
  }
  return 0;
}