#include <iostream>
using namespace std;
int main()
{
  int n,i,j,k;
  cin >> n;
  for(i=1;i<=n;i++){
    cin >> j;
    cout << "Case " << i << ":" << endl;
    for(k=0; k<10; k++){
      j *= j;
      j = (j % 1000000) / 100;
      cout << j << endl;
    }
  }
  return 0;
}