#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
  int n;
  cin>>n;
  for(int k=0;k<n;k++){{
      int a;
      cin>>a;
      printf("Case %d:\n",k+1);
      for(int i=0;i<10;i++){
	long long sq=a*a;
	long long s=sq;
	s/=1000000;s*=1000000;
	sq-=s;
	sq/=100;
	cout<<sq<<endl;
	a=sq;
      }
    }
  }
  return 0;
}