#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main() {

  int n;
  cin>> n;
  for(int num=0; num<n; num++) {
    int s;
    cin>> s;
    int rand_num=s;
    printf("Case %d:\n", num+1); 
    for(int i=0; i<10; i++) {
      rand_num*=rand_num;
      rand_num%=1000000;
      rand_num/=100;
      printf("%d\n",rand_num);
    }
  }
}