#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

class AOJ0137{
private:
  int val;
public:

  AOJ0137(int val):val(val){}

  string itos(int v){
    stringstream ss;
    ss << v;
    return ss.str();
  }

  void run(){
    rep(i,10){
      val *= val;
      string pre = itos(val);
      if(pre.size() < 8){	
	string p = string(8-pre.size(),'0')+pre;
	pre.clear(),pre = p;
      }
      string next = pre.substr(2,4);
      val = (atoi)(next.c_str());
      cout << val << endl;
    }
  }

};

int main(){
  int n;
  cin >> n;
  rep(i,n){
    
    int val;
    cin >> val;
    AOJ0137 ans(val);
    cout << "Case " << i+1 << ":" << endl;
    ans.run();
  }
return 0;
}