#include <iostream>
using namespace std;

int main(void)
{
  int i,j,n,h;
  cin >> n;
  for (i=1; i<=n; i++);{
    cin >> h;
  
    cout << "Case " << i << ":" << endl;

    for (j=1; j<=10; j++)
      { h=h*h;
        h=h/100;
        h=h%10000;
        cout << h << endl;}
  }

    return 0;
}
 