#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
using namespace std;

int main(){
  int n,i,c,s;
  cin >> n;
  for(i=1;i<=n;i++){
    cout << "Case " << i << ':' << endl;
    cin >> s;
    c=10;
   while(c){
     s=s*s;
     s/=100;
     s%=10000;
     cout << s << endl;   
     c--;
   }
  }
  return 0;
}
