#include <iostream>

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

  }
  return 0;
}