#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

typedef unsigned long long ull;

int main(){
  ull s;
  int T;
  cin >> T;
  for(int cs = 1 ; cs <= T ; cs++){
    ull ans[10];
    cin >> s;
    
    ull tmp = s*s;
    tmp /= 100;
    tmp %= 10000;
    
    ans[0] = tmp;
    
    for(int i = 1 ; i < 10 ; i++){
      ans[i] = ans[i-1]*ans[i-1];
      ans[i] /= 100;
      ans[i] %= 10000;
    }
    
    printf("Case %d:\n", cs);
    for(int i = 0 ; i < 10 ; i++){
      cout << ans[i] << endl;
    }
  }
  return 0;
}

    