#include<iostream>

using namespace std;

int main(){
  int i, j, n, s, t, u;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> s;
    cout << "Case " << i+1 << ":" << endl;

    for(j=0; j<10; ++j){
      s *= s;
      s /= 100;
      t = s/10000;
      s = s - t*10000;
      cout << s << endl;
    }
  }

  return 0;
}