#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

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

  }
  return 0;
}