#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int n;
  vector<int> v;
  cin>>n;
  v.reserve(n);
  for(i=0;i<n;i++)
    cin>>v[i];
  for(i=0;i<n;i++){
    cout<<"Case "<<i+1<<":"<<endl;
    for(j=0;j<10;j++){
      v[i]=v[i]*v[i]%1000000/100;
      cout<<v[i]<<endl;
    }
  }
  return 0;
}